c# - Linq where in 子句

标签 c# .net linq

我有层次结构,其中部门包含团队,团队包含代表。我想要做的是获取给定部门下存在的代表列表。我试过这样做:

var teams = from tms in db.Teams
            where tms.DepartmentID == DepartmentID
            select tms;

var TeamDelegates = from tds in db.J_TeamDelegates
                    where tds.TeamID in teams.TeamID //error here
                    select tds;

但团队集合不允许您像引用集合一样引用特定属性。我想说的是“在团队集合中选择所有具有 TeamID 的代表。”

最佳答案

var TeamDelegates = from tds in db.J_TeamDelegates
                    where teams.Any(x => x.TeamID == tds.TeamID)
                    select tds;

关于c# - Linq where in 子句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14986533/

相关文章:

asp.net - "AlternatingItemTemplate"在 Windows 资源管理器 9 中是否有效?

c# - 我应该为用户控件实现 IDisposable 吗?

c# - Linq 使用稍微复杂的选择列表

c# - 我的数据库的每个表都需要一个类吗?

c# - 如何解决 System.AccessViolationException C#

C# WCF 服务在重新连接后重新发送数据?这是什么属性?

c# - WPF 通过操作调整矩形大小不保持比例

c# - 事件与产量

c# - 使用 CaSTLe Windsor IoC 容器时添加服务初始化方法

c# - 如何在 LINQ 中按个案排序