How to build a LINQ query from text at runtime?

Posted by Danvil on Stack Overflow See other posts from Stack Overflow or by Danvil
Published on 2010-04-18T08:15:32Z Indexed on 2010/04/18 8:23 UTC
Read the original article Hit count: 167

Filed under:
|

I have a

class A {
   public int X;
   public double Y;
   public string Z;
   // and more fields/properties ...
};

and a List<A> data and can build a linq query like e.g.

var q = from a in data where a.X > 20 select new {a.Y, a.Z};

Then dataGridView1.DataSource = q.ToList(); displays the selection in my DataGridView.

Now the question, is it possible to build the query from a text the user has entered at runtime? Like

var q = QueryFromText("from a in data where a.X > 20 select new {a.Y, a.Z}");

The point being, that the user (having programming skills) can dynamically and freely select the displayed data.

© Stack Overflow or respective owner

Related posts about c#

Related posts about LINQ