这是我的 SQL 查询:
Select <a bunch of columns>
from fields f
join Table1 c1 on c1.fieldID = f.ID and c1.year = 2014
join Table2 fRes on f.ID = fRes.fieldID
join Table3 stst on f.ID = stst.fieldID
join Table4 model on c1.ID = model.yearID
left join Table5 fA on f.ID = fA.fieldID and fA.year = 2014
left join Table6 nA on f.ID = nA.fieldID and nA.year = 2014
where fA.sourcename IS NULL and nA.Sourcename IS NULL
LINQ 到 SQL:
from f in BasicDataAccess.Data.FieldsList
join c1 in BasicDataAccess.Data.Table1List on f.ID equals c1.fieldID
join fRes in BasicDataAccess.Data.Table2List on f.ID equals fRes.fieldID
join soilTst in BasicDataAccess.Data.Table3List on f.ID equals soilTst.fieldID
join modelRsNM in BasicDataAccess.Data.Table4List on c1.ID equals modelRsNM.YearID
join fA in BasicDataAccess.Data.Table5List on f.ID equals fA.fieldID into group1
from g1 in group1.Where(fA => fA.Year == reportYear).DefaultIfEmpty()
join nA in BasicDataAccess.Data.Table6List on f.ID equals nA.fieldID into group2
from g2 in group2.Where(nA => nA.Year == reportYear).DefaultIfEmpty()
where g1.sourceName == null && g2.sourceName == null
问题:执行时查询抛出 Nullreference 异常未处理..对象引用未设置为对象错误的实例..
我错过了什么?是否可以在 where 子句中引用左外连接表?请帮忙!