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;
}