我有一个运行良好的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.. }
但是,如果mymySTRINGVAR
为null或为空,则尝试不包含任何“ 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.. }
但是,如果mySTRINGVAR为null或为空,我将尝试不包含任何“ where”语句:
修改Where
如下:
tableC.Where(c => !string.IsNullOrEmpty(mySTRINGVAR) && c.tablefield == mySTRINGVAR)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句