I figured out a way to do this so that it matches the intended template system that uses ASP.NET dynamic data
Basically, the problem is that at compile time we donβt know what the base column can be filtered out, not to mention what type or name of the column it is - the first key that led me to the implementation path the solution was that all Filter controls have a GetQueryable method
Unfortunately, this method only works with an instance of IQueryable , not IQueryable<T> , which does not allow us to simply use the standard LINQ operators. We need a way to dynamically create a predicate (or a chain of predicates - in this case, however, all I wanted to do was get individual records and sort them), which we can then apply to IQueryable
Unfortunately, there is no built-in implementation in Dynamic LINQ, so we have to use expression trees. The second hint on how to solve this problem is that the IQueryable object provides a collection of .Expressions
We need to create an expression tree to represent the predicate (to select in this case, the choice), then attach it to IQueryable and return it. This, of course, was not an obvious or direct task, and of course I did not find that expression trees are easy to understand, but this is how I solved the problem.
source share