我有一个运行良好的 linq 查询,但是,如果我有一个空的,我想避免使用整个“where”过滤器mySTRINGVAR
,但是当我包含 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
但是,如果 my为空或为空,我将尝试不包含任何“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.. }