fib*_*ics 49 c# sql linq entity-framework
我必须列出要分配给" 员工 "的所有" 班次 "数据,但如果员工数据中已存在班次数据,则不得包括班次数据.我们来看看图片样本.

此查询解决了该问题.我在这里找到了这个:
Scott的博客
select * from shift where not exists
(select 1 from employeeshift where shift.shiftid = employeeshift.shiftid
and employeeshift.empid = 57);
Run Code Online (Sandbox Code Playgroud)
让我们看看结果:
现在我的问题是,我怎么能在linQ中做到这一点?我正在使用实体框架.
希望有人能提供帮助.非常感谢!!!
Ars*_*yan 88
from s in context.shift
where !context.employeeshift.Any(es=>(es.shiftid==s.shiftid)&&(es.empid==57))
select s;
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助
hyp*_*hyp 24
结果sql会有所不同,但结果应该是相同的:
var shifts = Shifts.Where(s => !EmployeeShifts.Where(es => es.ShiftID == s.ShiftID).Any());
Run Code Online (Sandbox Code Playgroud)