c# - 如何使用 LINQ 选择 WHERE NOT EXIST?

标签 c# sql linq entity-framework

我必须列出要分配给“员工”的所有“shift”数据,但如果员工数据中已存在轮类数据,则不得包含该数据。让我们看看图像样本。

No filtering yet

这个查询解决了这个问题。我在这里找到了这个:
Scott's Blog

select * from shift where not exists 
(select 1 from employeeshift where shift.shiftid = employeeshift.shiftid
and employeeshift.empid = 57);  

让我们看看结果:

Filtered

现在我的问题是,我怎样才能在 linQ 中做到这一点?我正在使用 Entity Framework 。
希望有人能帮忙。非常感谢!!!

最佳答案

from s in context.shift
where !context.employeeshift.Any(es=>(es.shiftid==s.shiftid)&&(es.empid==57))
select s;

希望对你有帮助

关于c# - 如何使用 LINQ 选择 WHERE NOT EXIST?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9031008/

相关文章:

c# - 如何避免属性递归

c# - OnCollisionEnter 未检测到

c# - 用于方法或属性的 Visual Studio UML 2010 代码生成

php - SQL Server : Given a year find everything (inclusive) from the year previous and given year

Python 加载一组 .csv 文件到 MySQL

C# CopyToDataTable 方法不起作用

c# - 如何理解 ASP.Net 中的基本开场白,页面标签?

sql - 如何使用SQL查询从表中删除重复项

c# - 检查列表中包含的 LINQ 方法(不考虑空格)

.net - 使用 linq 对相邻值进行分组