score:3

Accepted answer
int requiredId = ...   
var usersInReqdDept = Users.Where(u => u.Departments
                                        .Any(d => d.DepartmentId == requiredId));

If the Departments list can be null, you will need a null-check in the Where clause.

If you want to search the Departments list instead,

int requiredId = ...   
var usersInReqdDept = Departments.Single(d => d.DepartmentId == requiredId)
                                 .Users;

Of course, this will throw an exception if such a department doesn't exist.


Related Articles