views:

555

answers:

2

I need to build a dynamic linq query with or operators. I have seen PredicateBuilder but that is in C# and my project is in VB. Basically I need to build a WHERE clause similar to this:

Where((this = 1 AND that = 2) OR (this = 1 AND that = 4) OR (this = 2 AND that = 4))

but the problem is the number will have to be determined dynamically at runtime, and added using a loop, like

for each item in myItems
    query = query.OR (this = item.a AND this = item.b)
next

How could I go about doing that?

A: 

Have you looked into the LINQ Dynamic Query Library?

RichardOD
yeah I was aware of that but I didn't think it met my needs really, I'd have to dynamically build the sql using concatenation which is highly unwanted by my client. I actually just got linqkit and predicatebuilder working!
Ryan
+1  A: 

Got the LinqKit.dll working, now using PredicateBuilder even with my VB project and it works very well!

For anyone else needing this see http://rocksthoughts.com/blog/archive/2008/04/10/linq-to-sql-dynamic-queries-3-ands--ors-together.aspx, very good article on how to do this.

Ryan