I want to search my db with different keys. According to the input, there may be 1 key to 10 keys. Is there a way to add OR/AND clauses to my Linq query dynamically?
For AND clauses it is simple:
var feedList = from feed in ctx.Feed;
foreach(var key in keys){
feedList = feedList.Where(x=> content.contains(key));
}
var resultQuery = feedList.Select(x=> new {....});
For OR you will need to use Expressions
or try LinqKit and its predicates :
var predicate = PredicateBuilder.False();
foreach(var key in keys){
predicate = predicate.Or(x=> content.contains(key));
}
var resultQuery = ctx.Feed.Where(predicate).Select(x=> new {....});