Linq where in paragraph

I have a hierarchy in which the Department contains teams and teams containing delegates. What I'm trying to do is get a list of delegates who exist within this Department. I tried to do it like this:

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; 

But the collection of commands does not allow you to refer to a specific property as a collection. What I'm trying to say is "Select all delegates with TeamID in team collections."

+4
source share
4 answers
 var TeamDelegates = from tds in db.J_TeamDelegates where teams.Any(x => x.TeamID == tds.TeamID) select tds; 
+7
source

I think you can use the connection here.

 var TeamDelegates = from tms in db.Teams where tms.DepartmentID == DepartmentID join tds in db.J_TeamDelegates on tms.TeamID equals tds.TeamID select tds; 
+2
source
  var TeamDelegates = db.Teams .Where(tms => tms.DepartmentID == DepartmentID) .SelectMany(tms => db.J_TeamDelegates .Where(tds => tds.TeamID == tms.TeamID)) 
+1
source
 var delegates = db.Departments .Where(department => department.ID == 123) .SelectMany(department => department.Teams) .SelectMany(team => team.Delegates); 
+1
source

All Articles