c# - Joining multiple where clauses in LINQ as OR instead of AND -


Is there any way to join LINQ where as or

  Var ints = new [] {1, 3, 5, 7}; Var query = Choose from IT; Query = query Where (q = & gt; q == 3); Query = query..here (q = & gt; q == 7);  

I have the ability to add dynamically whatever I want, where the clause but instead of them or instead of

If you want to stay with your strong-typing link, then you should look at LinqKit and predicate building. I have used something similar for this and got it to work well with filter and / or stacking.

Check out for more information in depth, here is a logging from my code:

  // Setup initial bill obj then stacks on others: basePredicate = basePredicate. And (p = & gt; wrong); Var predicate1 = PredicateBuilder.True & lt; Person & gt; (); Foreign exchange (Searchfirm parm in parse) {switch (parm.field) {case "first name": predicate1 = predicate1.And (p = & gt; P.Efnstein T.R.M.). ToLower () includes (SVLE) ); break; // etc ...}} // To set stacking, run a switch based on your and / or ultimate value: if (Parm.is and) {basePredicate = basePredicate.And (predicate1); } And {basePredicate = basePredicate.Or (predicate1); }  

Comments