Linq Select语句-不在何处 [英] Linq Select Statements - Where Not In

查看:102
本文介绍了Linq Select语句-不在何处的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写等效于以下内容的LINQ语句:

I'm trying to write up the LINQ statement that is equivalent to:

select e.EmployeeID, EmployeeName = e.FirstName + ' ' + e.LastName
from Employees e
where e.EmployeeID not in
(
    select EmployeeID from Managers
)

我认为我与以下内容非常接近:

I think I'm pretty close with the following:

from e in Employees
where e.EmployeeID !=    // This is where I'm lost
(
    from m in Managers select m.EmployeeID
)
select new
{
    e.EmployeeID,
    EmployeeName = e.FirstName + ' ' + e.LastName
}

我正试图将其放入Html.DropDownList.

I'm trying to put this into a Html.DropDownList.

推荐答案

我不确定这是什么正确的查询符号,但是下面的扩展语法可以完成工作

I'm not exactly sure what the proper query notation for this is, but the following expanded syntax will get the job done

var result = Employees
  .Where( e => !Managers.Where(m => m.EmployeeId == e.EmployeeId).Any())
  .Select( e => new { EmployeeId = e.EmployeeId, EmployeeName = e.FirstName + ' ' + e.LastName);

这篇关于Linq Select语句-不在何处的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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