我的mongodb模型看起来像这样
"clienteId" : "123",
"devices" : [
{
"deviceId" : "234",
"deviceType" : "ios"
}
]
我在这个集合上调用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; }
}
}
我想使用LINQ,如何转换内部列表?
答案 0 :(得分:0)
找到它,它比我想的要简单得多:)
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()