多个WHERE。是否有可能只能在LINQ中执行特定的WHERE?

时间:2017-10-05 01:59:48

标签: entity-framework linq

我想在某种情况下只执行此操作

somelist.Where(x => x.isTest == true && x.status == request.StatusDescription &&
        (x.reqdate >= request.ReferenceDateFrom && x.reqdate <= request.ReferenceDateTo))

和这个用于其他条件

somelist.Where(x => x.status == request.StatusDescription
       && (x.reqdate >= request.ReferenceDateFrom && x.reqdate <= request.ReferenceDateTo))

1 个答案:

答案 0 :(得分:3)

怎么样?
var somelist=somelist.Where(x => x.status == request.StatusDescription
       && (x.reqdate >= request.ReferenceDateFrom && x.reqdate <= request.ReferenceDateTo))


if(condition==true){
somelist = somelist.Where(x => x.isTest == true)
 }