【发布时间】:2012-11-12 10:16:56
【问题描述】:
我有 3 张桌子。
例如客户、公司和地址。
客户已获得公司的参考。
公司有 2 个可以为空的地址引用(账单和运输),因此在某些情况下地址可能不存在。
我需要进行连接查询,但如果Company.BillingAddress 或Company.ShippingAddress 等于null,我不会得到所有数据。
我试过了(但它是错误的查询):
var res = (from client in context.Clients
join clientCompany in context.Companies
on client.ClientCompanyId equals clientCompany.Id
into clientCompanyJoin
from company in clientCompanyJoin
join addressBilling in context.Addresses
on company.BillingAddressId equals addressBilling.Id
join addressShipping in context.Addresses
on company.ShippingAddressId equals addressShipping.Id
select new
{
Client = client,
Company = company,
BillingAddress = ???????
ShippingAddress = ???????
}
);
您能帮我做一个连接查询或解释一下如何做吗?
谢谢。
【问题讨论】:
-
加入什么到什么?返回类型的结构应该是什么?可以贴一些代码或伪代码吗?
标签: c# linq entity-framework nullable