c# - LINQ,左连接,仅获取连接表中的空位置

标签 c# linq left-join

我想对两个表进行左外连接,但我只想返回第一个表的结果,而第二个表没有记录(null)。

 var agencies = from a in agencyList
                           join aa in joinTable
                           on a.AgencyId equals aa.AgencyId into joined
                           from aa in joined.DefaultIfEmpty()
                           where aa == null)
                           select a;

但这并不排除 aa 的非 null 值,并且返回所有记录,就像没有 'where aa == null' 一样。

感谢任何帮助。谢谢。

最佳答案

关于:

var agencies = from a in agencyList
                           where (from aa in joinTable where aa.AgencyId == a.AgencyId select aa).Count() == 0
                           select a;

关于c# - LINQ,左连接,仅获取连接表中的空位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2876555/

相关文章:

linq - Linqpad 中的 UserQuery 是什么?

c# - 如何使用 F# 中的 LINQ 提供程序?

c# - 使用 Entity Framework Fluent API 的一对一可选关系

javascript - 使用数字格式化文本框 OnfocusOut/OnBlur

c# - Concat() 实际上如何加入较低级别的集合?

php - 从左联合查询中获取更多结果

Mysql 左连接多个1到多个表

c# - Linq group by 然后只获取其中一项

c# - 显示 'saved' 标签 2 秒然后在 c# asp.net 中隐藏

php - 使用 Doctrine 按特定列连接表