我试图左连接三个表使用defaultIfEmpty分配空值,如果在第二个表中没有匹配,然后我使用第二个表值加入第三个表。
var test = (from Eqpt in Eqpts
join SystemEqpt in FleetSysEqpt on SystemEqpt.ID equals eqpt.SwCompanyEqptKey into sysEqptTemp
from a in sysEqptTemp.DefaultIfEmpty()
join System in System on a.SwFleetSystemKey equals System.ID
)
当'a'变成null时,我得到null对象引用错误。有什么建议来检查'a'是否为空,而加入
您只需要添加一个where
条件
var test = (from Eqpt in Eqpts
join SystemEqpt in FleetSysEqpt on SystemEqpt.ID equals eqpt.SwCompanyEqptKey into sysEqptTemp
from a in sysEqptTemp.DefaultIfEmpty()
join System in System on a.SwFleetSystemKey equals System.ID
where a != null
)