"Object reference not set to an instance of an object" even when I checked null

.net, c#, linq, null, reference

Solution

One of your rooms in the enumerable is null. Do this:

return room.Where(r => r != null)
           .SelectMany(r => r.Beds);

Problem

I have `Room` and `Bed` EF classes which each of `Room` have some `Bed`s.when I use this LINQ statement: ``` IEnumerable<Room> room=... if (room == null || !room.Any()) return null; return room.SelectMany(r=>r.Beds); ``` give me this error: Object reference not set to an instance of an object. in `return` line.

Original source

Related problems