Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Linq选择嵌套列表_C#_Linq_List_Mongodb - Fatal编程技术网

C# Linq选择嵌套列表

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 =

我的mongodb模型是这样的

 "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()