我有两个表“ Employees”和“ EmployeesCompanies”,“ Employees”包含所有雇员的列表,而“ employeescompanies”包含与该雇员关联的所有公司的列表:
Table 1 (Employees) EmployeeID 1 2 3 Table 2 (EmployeesCompanies) EmployeeID 1 2
I want to return3 which is the missing record from EmployeesCompanies, here is the linq code I'm using:
var queryOrphanedEmployees = (from a in db.Employees
join b in db.EmployeesCompanies
on a.EmployeeID equals b.EmployeeID
into outer
from c in outer.DefaultIfEmpty()
select new { a.EmployeeID}).ToList();
但是,这返回:
1个
2
这与我想要的完全相反。
最佳答案
如果正确设置了外键,则应该能够执行以下操作
from e in Employees
where !e.EmployeesCompanies.Any()
select e