我在EntityModel中有3个实体:Customer,CustomerAddress(这是带有Ids和orderOnControl列的联结实体,不能在模型中省略)和Address。我需要使用地址对FULL JOIN Customer进行linq查询。 SQL中的这个查询很简单:
select e1.[AddressID], e1.City, e3.CustomerID, e3.LastName from [SalesLT].[Address] as e1
full join [SalesLT].[CustomerAddress] as e2 on e1.[AddressID] = e2.[AddressID]
full join [SalesLT].[Customer] as e3 on e2.CustomerID = e3.CustomerID
但是我需要用linq写这个,我找到了答案,其中有2个实体具有多对多关系,但无法找到任何有结点实体,我将不胜感激任何提示
答案 0 :(得分:0)
给它一个机会。此LINQ语句将通过联结表CustomerAddress将客户加入地址。
var query = from ca in context.CustomerAddress
join a in context.Address on ca.AddressId equals a.AddressId
join c in context.Customer on ca.CustomerId equals c.CustomerId
select new { a.AddressId, a.City, c.CustomerId, c.LastName };