The help file that came with Dynamic Linq in the CSharpSamples.zip does not show any examples of using contains or like.
Are there any simple workarounds for doing this? i.e where (col like @col) doesn't work.
The Dynamic source file includes a helper library that allows you to express LINQ queries using extension methods that take string arguments instead of type safe operators. To use the Dynamic Expression API, you could simply copy/paste the Dynamic source file in your project.
LINQ Contains is quantifier operator. In LINQ Contains it also checks with the data sources, to check whether the collection of lists contains their desired element or not, and then it returns the result as either true or false based on the expected outcomes of the result.
The Dynamic LINQ library exposes a set of extension methods on IQueryable corresponding to the standard LINQ methods at Queryable, and which accept strings in a special syntax instead of expression trees.
Here is the answer! The Dynamic Linq does support the . operator,
According to the docs:
"Instance field or instance property access. Any public field or property can be accessed."
Thus, it is possible to use this syntax
.Where("MyColumn.Contains(@0)", myArray)
Thanks for all the suggestions! And thanks to me for finding the solution.
For me the solution was outerIt.
class User { public string Name { get; set; } } ... IQueryable<User> query = db.Users; ... query = query.Where("@0.Contains(outerIt.Name)", list);
Note that outerIt is kind of a keyword built in the library (you don't need to modify it as you can read it in an answer here). You can access the property of your query's type through it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With