where linq查询中的语句c#

NUL*_*ULL 1 c# sql linq asp.net-mvc

我有一个完美的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.. }
Run Code Online (Sandbox Code Playgroud)

但是,如果我mySTRINGVAR为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.. }
Run Code Online (Sandbox Code Playgroud)

Hab*_*bib 5

但是,如果我的mySTRINGVAR为null或为空,我试图不包含任何"where"语句:

修改之Where类:

tableC.Where(c => !string.IsNullOrEmpty(mySTRINGVAR) && c.tablefield == mySTRINGVAR)
Run Code Online (Sandbox Code Playgroud)