C# Linq选择嵌套列表
我的mongodb模型是这样的C# Linq选择嵌套列表,c#,linq,list,mongodb,C#,Linq,List,Mongodb,我的mongodb模型是这样的 "clienteId" : "123", "devices" : [ { "deviceId" : "234", "deviceType" : "ios" } ] clientes = cursor.Select(c => new Client() { ClientId = c.ClientId, devices = c.Devices.Select(d =
"clienteId" : "123",
"devices" : [
{
"deviceId" : "234",
"deviceType" : "ios"
}
]
clientes = cursor.Select(c => new Client()
{
ClientId = c.ClientId,
devices = c.Devices.Select(d => new Client.Device()
{
DeviceId = d.DeviceId,
DeviceType = d.DeviceType
}).ToList()
}).ToList()
我在这个集合上调用findAll,并试图将它转换为一个如下所示的对象列表
public List<Client> clients { get; set; }
public class Client
{
public string ClientId { get; set; }
public List<Device> devices;
public class Device
{
public string DeviceId { get; set; }
public string DeviceType { get; set; }
}
}
clientes = cursor.Select(c => new Client()
{
ClientId = c.ClientId,
devices = c.Devices.Select(d => new Client.Device()
{
DeviceId = d.DeviceId,
DeviceType = d.DeviceType
}).ToList()
}).ToList()
公共列表客户端{get;set;}
公共类客户端
{
公共字符串ClientId{get;set;}
公开设备清单;
公共类设备
{
公共字符串设备ID{get;set;}
公共字符串设备类型{get;set;}
}
}
我想使用LINQ,如何转换内部列表?找到它,比我想的简单多了:)
clientes = cursor.Select(c => new Client()
{
ClientId = c.ClientId,
devices = c.Devices.Select(d => new Client.Device()
{
DeviceId = d.DeviceId,
DeviceType = d.DeviceType
}).ToList()
}).ToList()