csharp linq distinct group by nested list

Code Example - csharp linq distinct group by nested list

                
                        var result = hotels.SelectMany(hotel => hotel.RoomType.Select(room => new { Id = room.RoomId, Hotel = hotel }))
                   .GroupBy(item => item.Id)
                   .Select(group => group.FirstOrDefault());