Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
118 views
Welcome To Ask or Share your Answers For Others

1 Answer

You may want to take a look at PredicateBuilder


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...