多个左外连接

时间:2016-06-30 18:24:11

标签: c# entity-framework linq left-join

我想在LINQ中使用具有多个Left连接的Entity Framework实现一个查询,但我得到一个空引用异常,例如:

var leftJoin = (from c in discountsList

join suc in discountsDepartmentList
on c.ListCode equals suc.ListCode

join rule in RulesList
on suc.ListCode equals rule.ListCode

join excepcion in ExceptionList
on new { suc.ListCode, rule.CategoryKey } equals new { excepcion.ListCode, excepcion.CategoryKey }
into ex from exc in ex.DefaultIfEmpty()

join prenda in prendas
on new { rule.CategoryKey , **leftExcepcion.CodigoArticulo** *-> comes with null* } equals new { prenda.CategoryKey , prenda.CodigoArticulo }

into pp
from leftPrenda in pp.DefaultIfEmpty()
where c.Activo == true && suc.deparmentCode== deparmentCode
select new
{

}
).Distinct();

我不知道如何检查leftExcepcion是否带有null,所以我收到了这个错误。 提前谢谢。

0 个答案:

没有答案