如果我使用2个左连接执行LINQ查询,我很好,但是一旦我添加了第三个左连接,我的“from”中的初始表将不再可用于第3个左连接并且我收到错误:
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
上收到错误,如果我重新排序左连接并不重要,它仍然是第三个错误。