Using Predicate Builder of LINQKit for Or-clauses in LINQ
LINQ does not support Or-clauses by default. As I need this functionality in my current project, I am using the Predicate Builder which is part of the LINQKit. This class allows you to add an Or-clause to your LINQ-Query:
IQueryable<Product> SearchProducts (params string[] keywords){ var predicate = PredicateBuilder.False<Product>(); foreach (string keyword in keywords) { string temp = keyword; predicate = predicate.Or (p => p.Description.Contains (temp)); } return dataContext.Products.Where (predicate); }
This is very helpful!
You can find LINQKit on NuGet.