How to make a compound “or” clause in Linq?

前端 未结 5 1716
南笙
南笙 2021-01-05 23:00

If you\'re adding \"and\" conditions to a Linq query, it\'s easy to do it like so:

var q = MyTable;
if (condition1)
  q = q.Where(t => t.Field1 == value1)         


        
5条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-05 23:24

    Use the following:

    var q = MyTable;
    q = q.Where(
         t => (condition1 && t.Field1 == value1) || (condition2 && t.Field2 > t.Field3));
    

提交回复
热议问题