gpt4 book ai didi

sql - Linq to SQL 左外连接不

转载 作者:行者123 更新时间:2023-12-04 21:53:59 24 4
gpt4 key购买 nike

我有两个表“Employees”和“EmployeesCompanies”,Employees 包含所有员工的列表,employeecompanies 包含与员工关联的所有公司的列表:

Table 1 (Employees)EmployeeID123Table 2 (EmployeesCompanies)EmployeeID    12

I want to return 3 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();

但是这会返回:

12

这与我想要的完全相反。

最佳答案

如果你已经正确设置了外键,你应该能够做这样的事情

from e in Employees
where !e.EmployeesCompanies.Any()
select e

关于sql - Linq to SQL 左外连接不,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18640427/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com