As proposed by Guru Stron, I've give a try to LINQKit, that I didn't know.
The code I searched for hours was waiting for me right here!
IQueryable<Product> SearchProducts (params string[] keywords)
{
var predicate = PredicateBuilder.New<Product>();
foreach (string keyword in keywords)
{
string temp = keyword;
predicate = predicate.Or (p => p.Description.Contains (temp));
}
return dataContext.Products.Where (predicate);
}
Thanks a lot! You saved my day.
But it's really strange that we can't do it without an external library.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…