0

I have 3 entities in EntityModel: Customer, CustomerAddress (this is junction entity with Ids and orderOnControl columns and cant be ommited in model) and Address. I need to make linq query to FULL JOIN Customer with Address. This query in SQL is plain:

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

but I need to write this with linq, I found answers where there are 2 entities with many-to-may relation, but couldn't find any with junction entity, I would appreciate any tips

abatishchev
  • 98,240
  • 88
  • 296
  • 433
przemo
  • 1
  • 2

1 Answers1

0

Give this a shot. This LINQ statement will join Customers to Addresses through the junction table 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 };
Mike Hixson
  • 5,071
  • 1
  • 19
  • 24
  • It joins elements which have join condition, I need to list all rows from right and left table. Maybe I will just concat elements that doesn't have id in junction table to result of your query... – przemo Jun 18 '14 at 06:41
  • It will join but it will give us the result of inner join not full join – Ujjwal Kumar Gupta Aug 15 '16 at 06:12