Using special property names in Dynamic LINQ

c# dynamic-linq linq

Question

I'm constructing a Dynamic LINQ query like this:

"Guid=Guid(\"" + entityId + "\")"

This is eventually passed into a .Where() query, somewhere in the code that I call.

I'm getting this error:

ParseException: '.' or '(' expected

This seems to be because it doesn't find the Guid property, but rather the Guid function.

How can I query on the Guid property of my object?

1
0
12/10/2013 2:37:30 PM

Accepted Answer

Guid is indeed a keyword. You can escape keyword identifiers by prefixing them with @.

The correct expression looks like this:

"@Guid=Guid(\"" + entityId + "\")"
1
12/10/2013 4:39:49 PM

Popular Answer

Just to tidy up Kendall's answer I think the more elegant approach is to let Dynamic LINQ handle the type conversions by using parameterized queries.

myIqueryable1.Where("@Guid=@0", entityId)


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