従業員テーブル
Employee_ID int
Employee_Name varchar(50)
販売テーブル:
Sales_ID int
Employee_ID int
Sale_Amount money
標準 SQL 選択
Select
*
From Employee emp
left outside join
Sales
on
s.Employee_ID = emp.Employee_ID
標準 SQL の結果 (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
次に、Linq To Entities に取り組みます
Dim query = From emp In entiites.Employee _
From sales In emp.Sales _
Select _
emp, _
sales
Linq To Entities の結果 (Employee_ID 3 と 4 はどこにありますか)
1: Emp1: 150.0000
1: Emp1: 500.0000
2: Emp2:
250.0000 5: Emp5: 700.0000
左外部結合を使用して、Linq to Entities で試してください。
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
次に、DefaultIfEmpty を使用してこのエラーが発生します。
LINQ to Entities はメソッド 'System.Collections.Generic.IEnumerable 1[m12Model.Sales] DefaultIfEmpty[Sales](System.Collections.Generic.IEnumerable
1[m12Model.Sales])' メソッドを認識せず、このメソッドはストア式に変換できません。