如题,有三个表,通过table1串出table2,再通过table2串出table3,其中table2, table3有可能为空,所以选择使用左连接查询。
sql: select * from table1 a left join table2 b on a.id = b.id left join table3 c on b.name = c.name;
sql 语句查询没有问题。
linq 写法:
from a in table1 join b in table2 on a.id equals b.id into temp from temp2 in temp.DefaultIfEmpty() join c in table3 on temp2.name equals c.name into temp3 from temp4 in temp3.DefaultIfEmpty() select new {
...
};
查询时,会显示table3处 未将对象实例化,
请问我应该怎么写这段Linq.
分不多,十分感谢~
我测试的时候,会在 temp2
处报 null
错,因为两边表数据不一致,使用可为空 temp2?
之后修复
你是在select 的时候报错把?
@Result_For: 是的