双连接查询返回多个相同的记录而不是唯一的记录
我正在尝试使用此查询获取一个人所属的团队。问题是它返回了该人所在团队的所有部门的团队(我得到了多个相同的记录)。我想我必须替换 .contains 但我不知道用什么来替换,因为我是一个完全的新手,而且我找不到任何有用的双连接示例。我必须改变什么才能使其按预期工作?提前致谢。
public IQueryable<Team> GetTeamsByPersonID(int id)
{
return from t in entities.Teams
join d in entities.Departments
on t.TeamID equals d.TeamID
where (from p in entities.Person_Departments
join dep in entities.Departments
on p.DepartmentID equals dep.DepartmentID
where p.PersonID == id
select dep.TeamID).Contains(d.TeamID)
select t;
}
I am trying to get the teams a person belongs to using this query. The problem is that it returns the teams of all the departments of the team the person is in (I get multiple identical records back). I guess I have to replace the .contains but I can't figure out with what as I'm a complete newb and I can't find any helpful examples with double joins. What do I have to change to make it work as intended? Thanks in advance.
public IQueryable<Team> GetTeamsByPersonID(int id)
{
return from t in entities.Teams
join d in entities.Departments
on t.TeamID equals d.TeamID
where (from p in entities.Person_Departments
join dep in entities.Departments
on p.DepartmentID equals dep.DepartmentID
where p.PersonID == id
select dep.TeamID).Contains(d.TeamID)
select t;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试
try