如何使用LINQ选择哪里不存在? [英] How to SELECT WHERE NOT EXIST using LINQ?

查看:99
本文介绍了如何使用LINQ选择哪里不存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须列出要分配给员工的所有转移数据,但如果已经存在员工的数据,则不得包含转移数据。让我们看看图像的样本。

I have to list all "shift" data to be assigned to an "employee" but shift data must not be included if it is already existing in employee's data. Let's see the image sample.

此查询解决了问题。我在这里找到:

Scott的博客

This query solves the problem. I found this here:
Scott's Blog

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

我们来看看结果:

img src =https://i.stack.imgur.com/STsh2.pngalt =Filtered>

现在我的问题是,我该怎么做这在linQ?我正在使用实体框架。

希望有人可以帮助。非常感谢!!!

Now my question is, how could I make this in linQ ? I'm using entity framework.
Hope someone could help. Thanks a lot!!!

推荐答案

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

希望这有助于

这篇关于如何使用LINQ选择哪里不存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆