简体   繁体   中英

Dynamic string in linq c#

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.

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

Also rewrite the query like this:

_dbContext.TmRecords.Where("city = @0", "london");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM