【发布时间】:2012-01-27 09:07:11
【问题描述】:
我必须列出要分配给“员工”的所有“班次”数据,但如果班次数据已经存在于员工的数据中,则不得包含该数据。让我们看一下图像示例。
这个查询解决了这个问题。我在这里找到了这个:
Scott's Blog
select * from shift where not exists
(select 1 from employeeshift where shift.shiftid = employeeshift.shiftid
and employeeshift.empid = 57);
让我们看看结果:
现在我的问题是,我怎样才能在 linQ 中做到这一点?我正在使用实体框架。
希望有人能帮忙。非常感谢!!!
【问题讨论】:
-
你可以简单地做一个连接......如果右记录不存在,则不应包含左记录
-
@AndreasNiedermair 你能举个例子吗?我加入了很多,但我没有找到合适的。
-
您可以参考其他 SO 主题:stackoverflow.com/questions/899090/linq-where-not-exists for Linq 中的 WHERE NOT IN 子句
-
LINQ - Where not exists 的可能副本
标签: c# sql linq entity-framework