I am using linq in my application. Query has several conditions .Where(a => !one || a.id == 1)
.
bool one = false;
bool two = false;
bool three = fal
If you need to or
the ids in your where predicate you can use Enumerable.Contains() method like this:
var ids = new[]{1, 2, 3};
db.type.Where(w => ids.Contains(w.id));
However, what I assume you want is a way to dynamically create the predicate for the Where
clause and believe me, using flags with or conditions is not the way to do this; not only the condition will make the other persons reading that code cry blood but it will also lead to bad query performance.
The proper way to do this is using a PredicateBuilder. Take a look at the article to see how it should be used and what it does.
There's a caveat to it however - it won't work in Entity Framework
or nHibernate
. To create one for the the above ORMs, use this blog post on Universal predicate builder.