views:

1098

answers:

3

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?

+4  A: 

Actually, there is a specific library from Microsoft (System.Linq.Dynamic) that comes with the C# VS2008 samples that supports this. Get it from here (Microsoft Download)

The library is included in the \LinqSamples\DynamicQuery directory of the samples of above download.

For extensive usage examples check this page: http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx

Alex
Ok, System.Linq.Dynamic looks like exactly what I'm looking for at first glance.However Dynamic linq only works on IQueryable and not IEnumerable.So this still leaves a bit of a problem.
Jabezz
+4  A: 
Marc Gravell
You SO copied me :) haha
Alex
Although Alex was first with the Dynamic LINQ library, the part that was missing was raised by Marc (sorry for missing that). You need the .AsQueryAble() extension method to be able to work with your collections.
Jabezz