Dynamic string in linq c#

.net c# dynamic-linq

Question

I have installed System.Linq.Dynamic dll and then tried to add string as the parameter of WHERE clause in Linq. But I am still getting error that the string parameter is supported by WHERE clause.

Code:

_dbContext.TmRecords.Where("city=london");

Error:

Severity Code Description Project File Line Error CS1503 Argument 2: cannot convert from 'string' to 'System.Linq.Expressions.Expression>' Extranet.Domain

Here the city parameter dynamically changes to some other parameter. So, I need to use dynamic queries in linq.

1
2
10/20/2016 10:04:00 AM

Accepted Answer

You should add using System.Linq.Dynamic; to your file.

Also rewrite the query like this:

_dbContext.TmRecords.Where("city = @0", "london");
7
10/20/2016 9:59:14 AM


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