如果我使用 2 个左连接进行 LINQ 查询,我很好,但是一旦我添加了第三个左连接,我的“from”中的初始表就不再可用于第三个左连接,我得到一个错误:
Source compile error, line ##: The name 'x' does not exist in the current context
例如:
from x in [TableX]
join a in [TableA]
on x.ItemNumber equals a.ItemNumber into aLeftJoin
from aLeft in aLeftJoin.DefaultIfEmpty()
join b in [TableB]
on x.ItemNumber equals b.ItemNumber into bLeftJoin
from bLeft in bLeftJoin.DefaultIfEmpty()
join c in [TableC]
on x.ItemNumber equals c.ItemNumber into cLeftJoin
from cLeft in cLeftJoin.DefaultIfEmpty()
select new
{
x.ItemNumber,
...
}
然后我在线得到错误,on x.ItemNumber equals c.ItemNumber into cLeftJoin
如果我重新排序左连接也没关系,它仍然在第三个连接上出错。