Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic LINQ - Is There A .NET 4 Version?

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:

  1. Is this sample library supported by Microsoft?
  2. Scott Guthrie's article is in regards to VS2008 (.NET 3.5). Is there a better option for .NET 4? Maybe something that was released with .NET 4 that accomplishes the same thing (or something very close)?

Thanks in advance!

like image 907
David Hoerster Avatar asked Mar 02 '11 03:03

David Hoerster


People also ask

Can you use Linq on dynamic?

The Dynamic LINQ library let you execute query with dynamic string and provide some utilities methods such as ParseLambda , Parse , and CreateClass .

What is Linq dynamic?

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.


1 Answers

You may want to take a look at PredicateBuilder

like image 108
Pero P. Avatar answered Sep 29 '22 05:09

Pero P.