Dynamic LINQ - Is There A .NET 4 Version?

21,737

Solution 1

You may want to take a look at PredicateBuilder

Solution 2

It should now be available. I could download it through NuGet: http://www.nuget.org/packages/System.Linq.Dynamic/

Solution 3

I don't think it's "supported" by Microsoft - it seems to be released under a public license, which says in part:

(E) The software is licensed “as-is.” You bear the risk of using it. The contributors give no express warranties, guarantees or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular purpose and non-infringement.

On your second question, I don't think there's a .NET 4 version. The 3.5 should work fine in a 4.0 project, and I don't think there's really much to add in. As I understand it, this was a nifty little library for doing those occasional, one-off string-based linq queries. Maybe you were for some reason manually sorting a grid, and needed to modify your collections sort order based on a string representing the property in question. Voila. I doubt you'll see a lot of effort put into adding a lot of features into this.

Share:
21,737
David Hoerster
Author by

David Hoerster

I like to consider myself a common sense evangelist, where I generally favor getting things to work well rather than adhering to a strict orthodoxy for orthodoxy's sake. I prefer consistency over the one-off solution, and will take a few hits off performance in order to achieve a more maintainable and scalable solution. I'm a developer, community enthusiast and family man. I'm also a C# MVP.

Updated on January 18, 2020

Comments

  • David Hoerster
    David Hoerster over 4 years

    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!