Currently, ASP.NET Dynamic Data Entities only supports filtering on boolean or Foreign Key relationships out-of-the-box
How would I implement a custom filter, based on a dropdown list of values to filter the rows by?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I figured out a way to do this, so that it fits within the intended templating system that ASP.NET Dynamic Data uses
Basically the problem with this is that we do not know at compile time what the underlying column that might be filtered on is, let alone what type or column name it is – the first clue that led me to the path to implementing a solution was that the Filter controls all have a method GetQueryable
Unfortunately, this method works on an instance of
IQueryablerather thanIQueryable<T>, thus preventing us from being able to simply use standard LINQ operators. What we need is a way to dynamically create a predicate (or chain of predicates even – in this case however, all I wanted to do was to get the distinct entries and sort them), which we can then apply to theIQueryableUnfortunately, there is no out of the box implementation of Dynamic LINQ, thus we must use expression trees – the second hint of how to solve this problem is the fact the
IQueryableobject exposes a .Expressions collectionWhat we need to do is create the expression tree to represent the predicate (for selecting distinct in this case) then attach it to the
IQueryableand return it. This was certainly not an obvious, nor straight-forward task and I certainly did not find expression trees easy to understand but therein was how I solved the problem.