0

enter image description hereHow to use leftouter join in entity framework query

I have two table one is item and other is stock available I want to get all items and also get its quantity from stock available table which depend upon the particular department

Nadeem
  • 651
  • 1
  • 13
  • 26

1 Answers1

2

For example LINQ Query

var query = (from p in dc.GetTable<Person>()
join pa in dc.GetTable<PersonAddress>() on p.Id equals pa.PersonId into tempAddresses
from addresses in tempAddresses.DefaultIfEmpty()
select new { p.FirstName, p.LastName, addresses.State });

SQL Translation

SELECT [t0].[FirstName], [t0].[LastName], [t1].[State] AS [State]
 FROM [dbo].[Person] AS [t0]
 LEFT OUTER JOIN [dbo].[PersonAddress] AS [t1] ON [t0].[Id] = [t1].[PersonID]
Likurg
  • 2,742
  • 17
  • 22