Dynamic select is not working for Guid name property

c# dynamic-linq select

Question

I have simple class:

class MyClass
{
    public Guid Guid { get; set; }
}

I have myClasses query that contains one item: new MyClass() { Guid = Guid.NewGuid() }

I'm trying to select Guid property from query :

var result = myClasses.Select($"new(Guid)");

But it is showing following exception:

System.Linq.Dynamic.ParseException: ''.' or '(' expected'

It seems Dynamic linq is mixing up my Guid property with System.Guid structure. How can I solve this issue?

Note: It works when I rename property

1
1
8/26/2019 11:24:03 AM

Accepted Answer

When using System.Linq.Dynamic.Core, you have 2 options:

  1. Use it
var result = myClasses.Select($"new(it.Guid)");
  1. Escape reserved name with a @
var result = myClasses.Select($"new(@Guid)");
1
8/27/2019 3:51:59 PM


Related Questions





Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow