I'm looking to use LINQ for some searching routines and wanted to have some dynamic where clauses. So, for example, if a user wants to search by city or search by state, I would have a dynamic LINQ Where<> call instead of creating two strongly typed LINQ expressions and then using the appropriate one based on how the user wants to search.
So I would like to do this:
String criteria="p.City='Pittsburgh'"; //or "p.State='PA'"
personData.Where(criteria)
instead of
personData.Where(p => p.City=="Pittsburgh");
or
personData.Where(p => p.State=="PA");
I came across a blog post by Scott Guthrie talking about Dynamic LINQ in the Visual Studio 2008 samples. This seems to do what I want, but my questions are:
Thanks in advance!
You may want to take a look at PredicateBuilder