Linq中的外部联接 - 类型界面在调用' SelectMany'

时间:2015-09-09 12:11:01

标签: c# linq left-join outer-join

我正在尝试在Linq中编写一个复杂的查询。我有6个tabes。

var contracts1 = (from c in ctx.Contracts
join a in ctx.Agents on c.AgentID equals a.AgentID into ca
from a in ca.DefaultIfEmpty
join cu in ctx.Customers on c.CustomerID equals cu.CustomerID into ccu
from cu in ccu.DefaultIfEmpty
join su in ctx.Suppliers on c.SupplierID equals su.SupplierID into csu
from su in csu.DefaultIfEmpty
join s in ctx.Sites on c.SiteID equals s.SiteID into cs
from s in cs.DefaultIfEmpty
join e1 in ctx.employees on c.EmployeeID equals e1.EmployeeID into ce1
from e1 in ce1.DefaultIfEmpty
select new { c, a, cu, su, s, e1 });

我需要编写一个返回所有契约的查询,即使这些外键中的任何一个为空。

我不确定是使用左外连接还是右外连接。我知道使用左外连接我们可以检索所有主行,即使没有子记录。我正在尝试相反的事情。我写了下面的查询

from a in ctx.Agents
from c in a.Contracts.DefaultIfEmpty
select new { c, a }

它无法编译。在拨打' SelectMany'时,错误消息是'类型界面失败。

我正在尝试一些非常简单的事情

JSON.stringify(json).replace("test1", "img")

没有' DefaultIfEmpty'

,它可以正常工作

我真的很感谢你的帮助。

0 个答案:

没有答案