The right way ... is this . I mean, you could write it like
sql.Where(x => x.Name == "aaaaa").Concat(sql.Where(x => x.Name == "bbbbb"));
but slower, disordered, and look weirder. I do not know what you are looking for, because the way you posted is the right way to do this.
However , it seems you want to dynamically build the expression (judging by your comment). If yes, then you are looking for PredicateBuilder :
var predicate = PredicateBuilder.False<YourType>(); var search = new[] {"aaaaa", "bbbbb"}; foreach (string y in search) { string name = y; predicate = predicate.Or(x => x.Name == name); } sql = sql.Where(predicate);
PredicateBuilder code is here .
source share