Sarath
Sarath

Reputation: 11

Using Dynamic Linq Select - Guid field throwing exception

My Database column name is "Guid" , Since the DB is mapping to many applications and also already in production I couldn't able to change the DB field,

Error Occurs only if Field Name is "Guid"

var query2 = db2.Charities.Select("New(Name as CharityName,City as City,new Guid as Guid)");

enter image description here

Upvotes: 1

Views: 89

Answers (1)

Stef Heyenrath
Stef Heyenrath

Reputation: 9830

When using System.Linq.Dynamic.Core you should be able to use the @ character to escape predefined names.

Example code:

var queryable = new[] { new { Id = 1, Guid = "a" } }.AsQueryable();

var result = queryable.Select("new (Id, @Guid, 42 as Answer)").ToDynamicArray();

See also example unit test

Upvotes: 1

Related Questions