添加第三个左连接会使初始表超出范围

时间:2013-09-12 21:56:16

标签: linq linq-to-sql join left-join

如果我使用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上收到错误,如果我重新排序左连接并不重要,它仍然是第三个错误。

0 个答案:

没有答案