Setup of the LINQ Dynamic Query Library

c# dynamic-linq linq

Question

I am having trouble setting up this Dynamic Linq Library so i can use Dynamic where clauses. Can someone advise me onhow to add this library to my project and reference correctly.

http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx

also seen in the post

Is there a pattern using Linq to dynamically create a filter?

thanks,

Update -

var x = ListofObjects.AsQueryable().Where("Some comparison");

Update -

After adding the Dynamic.cs library my project wont build with a bunch of compilation errors coming from that specific class. all similar to.

The namespace 'System.Linq.Dynamic' already contains a definition for 'DynamicOrdering' 
1
4
5/23/2017 10:08:34 AM

Accepted Answer

Seems to work fine for me:

public class SomeType
{
    public string var1;
    public string var2;
}

class Program
{
    static void Main(string[] args)
    {
        var myList = new List<SomeType>();

        myList.Add(new SomeType() { var1 = "abc", var2 = "abc" });
        myList.Add(new SomeType() { var1 = "def", var2 = "def" });

        foreach (var item in myList.AsQueryable().Where("var1=\"abc\""))
            Console.WriteLine("item.var1 = " + item.var1);
    }
}
0
1/4/2012 2:07:45 PM


Related Questions





Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow