【发布时间】:2017-10-18 18:09:51
【问题描述】:
我有一个嵌套列表,如下所示:
List<Hotel> Hotels;
public class Hotel
{
List<RoomType> RoomType;
}
public class RoomType
{
Room Room;
}
public class Room
{
int RoomId;
}
这有点令人费解,抱歉想不到更好的模型模型。这个想法是我有很多酒店,每个酒店都有很多房间类型,并且假设每个房间类型只有一个房间对象。
现在从酒店列表中,我只想选择所有 RoomId's.. 我被困在这里,同时尝试嵌套所有列表..
现在,我正在尝试这个:
//cant do this some invalid error
int[] AllRoomIds = Hotels.selectMany(x => x.Rooms)
.selectMany(y => y.RoomType.Room.Id).Distinct().ToArray()
//cant do this - z doesnt have anything
int[] AllRoomIds = Hotels.selectMany(x => x.Rooms)
.selectMany(y => y.RoomType)
.select(z => z.
请问我该怎么做?
访问嵌套列表中所有项目的所有 id.. 偶尔它会抱怨 cannot convert int to boolean 而我不知道这是什么意思...
谢谢..希望问题是可以理解的
【问题讨论】:
-
这能回答你的问题吗? Get All Children to One List - Recursive C#
标签: c# linq nested-lists