Dynamically building a LINQ query using the OR operator in VB
I need to create a dynamic linq query with operators or operators. I've seen PredicateBuilder, but it's in C # and my project is in VB. Basically I need to build a WHERE clause like this:
Where((this = 1 AND that = 2) OR (this = 1 AND that = 4) OR (this = 2 AND that = 4))
but the problem is that 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 can i do this?
+1
a source to share
2 answers
Got LinqKit.dll working now using PredicateBuilder even with my VB project and it works really well!
For those who need it 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 it.
+1
a source to share