Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I build up LINQ dynamically

I have a scenario where I have custom configured column names, associated operators like < > = between etc. and then a value associated.

I'm trying to determine if it is possible to build up a LINQ query with a dynamic (string) where clause?

I've noticed the Predicate.OR Preditcate.AND stuff, but that is not quite what I'm talking about.

Any suggestions?

like image 454
Jabezz Avatar asked Aug 18 '09 08:08

Jabezz


1 Answers

If you are talking about a string Where clause (rather than building the expression etc yourself) - then the Dynamic LINQ Library (in the 3.5 samples, IIRC) should suffice.

Note that the example below is for database usage; but you can use it with LINQ-to-Objects by calling .AsQueryable() on your in-memory data.

alt text

like image 94
Marc Gravell Avatar answered Oct 22 '22 16:10

Marc Gravell