我有一个完美的linq查询,但是,如果我有一个空的mySTRINGVAR
,我想避免整个“where”过滤器,但是当我包含if语句时它打破了查询!提前感谢您的帮助。
所以这就是我拥有的,这完美地运作!!:
var records = from school in schools
join tableA in tableAs on someid equals anotherid into tableC
from tableD in tableC.Where(c => c.tablefield == mySTRINGVAR).DefaultIfEmpty()
select new { etc.. }
但是,如果我的mySTRINGVAR
为空或空,我试图不包含任何“where”语句:
var records = from school in schools
join tableA in tableAs on someid equals anotherid into tableC
from tableD in tableC.DefaultIfEmpty()
select new { etc.. }
答案 0 :(得分:5)
然而,我试图不包括任何“where”声明,如果我的 mySTRINGVAR为null或为空:
修改Where
,如:
tableC.Where(c => !string.IsNullOrEmpty(mySTRINGVAR) && c.tablefield == mySTRINGVAR)