Dilshod K
Dilshod K

Reputation: 3032

Dynamic select is not working for Guid name property

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

Upvotes: 1

Views: 307

Answers (1)

Stef Heyenrath
Stef Heyenrath

Reputation: 9830

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)");

Upvotes: 1

Related Questions