Q:

Is it possible to filter child collections during a Linq.Where()?

I have an object heirarchy:
DeathStar.Floors.Departments.Rooms

At the moment, I'm only selecting floors that contain departments that have a room containing rebel scum being intimidated or injected by a droid:
var rebelScum = deathStar.Floors.Where(
                f=> f.Departments.Any(
                    d => d.Rooms.Any(
                        r => r.Occupant.Allegiance  == "Rebel"
                            && (r.InterrogationState == Interrogation.Intimidation
                                || r.InterrogationState == Interrogation.FloatyStabbyDroid)
                        )
                    )
                );

However, rebelScum will contain empty rooms in the same department as any rebel scum being interrogated.
Can I filter inside this .Where() to only return the occupied rooms?

A:

  IEnumerable<Room> roomsOccupiedByRebelScum = deathStar.Floors.SelectMany(f => f.Departments)
                                                .SelectMany(d => d.Rooms)
                                                .Where(r => r.Occupant != null && r.Occupant.Allegiance == "Rebel" && 
                                                (r.InterrogationState == Interrogation.Intimidation || r.InterrogationState == Interrogation.FloatyStabbyDroid)
                                                );

If you want to filter rooms, they must form the result of the query

