How to use Dynamic LINQ (System.Linq.Dynamic) for LIKE operation?

You can use .StartsWith(), .EndsWith() and .Contains() which will generate LIKE SQL with trailing, leading and surrounding wildcards respectively. Don't know of a way to generate a statement with an embedded wildcard tho.


Try using simply "CityName.Contains(@1)" this will convert to the proper lambda since its a method invocation on an accessible type.

something like:

var query =
db.Customers.
Where("CityName.Contains(@0) or CityName.Contains(@1)", "London", "USA")

Just tested it with the sample app that comes with the dynamic library and it generates the LIKE operator