Remember those old posts on Dynamic LINQ? You are probably aware that Microsoft has made its implementation available as a Nuget package, but, like I said, you already have it in your machine, hidden inside the System.Web.Extensions assembly.
In order to make it easier to use, I wrote a simple extension method that works with plain old IQueryable<T>. And here it is:
params Object[] values)
2: {
typeof(UpdatePanel).Assembly;
);
typeof(Boolean));
as Expression<Func<T, Boolean>>;
7:
return (query.Where(expression));
9: }
It even supports parameters! Just two simple examples – I am using Entity Framework, but you can use whatever you like, this is totally generic:
//without parameters
).ToList();
3:
//with parameters
, 100).ToList();
To make it clear, all parameters must be indicated as @0, @1, and so on. It is better to use them, because the database engine can reuse the execution plan.
There’s one limitation, though: you can’t compare each value on its own, you have to specify one of its properties. For example, you can’t have:
).ToList();
The @it parameter is not recognized, which is a pity.
Make sure you have references to both System.Web and System.Web.Extensions, this is required, and won’t affect anything.
As always, glad to be of service!