员工表
Employee_ID int
Employee_Name varchar(50)
销售表:
Sales_ID int
Employee_ID int
Sale_Amount 钱
标准 SQL 选择
Select
*
From Employee emp
left outer join
Sales s
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 Entity
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])' 方法,并且此方法无法转换为存储表达式。