Employee table
Employee_ID int
Employee_Name varchar(50)
Sales table:
Sales_ID int
Employee_ID int
Sale_Amount money
Standard SQL select
Select
*
From
Employee emp
left outer join
Sales s
on
s.Employee_ID = emp.Employee_ID
Standard SQL Results (The exact results I want using Linq to Entites)
1 Emp1 1 1 150.00
1 Emp1 2 1 500.00
2 Emp2 3 2 250.00
3 Emp3 NULL NULL NULL
4 Emp4 NULL NULL NULL
5 Emp5 4 5 700.00
Now to tackle Linq To Entities
Dim query = From emp In entiites.Employee _
From sales In emp.Sales _
Select _
emp, _
sales
Linq To Entities Result (Where is Employee_ID 3 and 4)
1: Emp1: 150.0000
1: Emp1: 500.0000
2: Emp2: 250.0000
5: Emp5: 700.0000
Try it with Linq to Entities with a left outer join:
Dim query = From emp In entiites.Employee _
Group Join sales In entiites.Sales _
On emp.Employee_ID Equals sales.Employee.Employee_ID _
Into sales_grp = Group _
From Sel_SalesGrp In sales_grp.DefaultIfEmpty() _
Select _
emp, _
Sel_SalesGrp
Then I get this error using DefaultIfEmpty:
LINQ to Entities does not recognize the method 'System.Collections.Generic.IEnumerable1[m12Model.Sales] DefaultIfEmpty[Sales](System.Collections.Generic.IEnumerable
1[m12Model.Sales])' method, and this method cannot be translated into a store expression.