我正在尝试创建嵌套对象,但出现此错误:
表达式树中不支持GroupBy方法: {document} .GroupBy(y => y.Select(z => z.DamageId))。
请帮助如何使查询工作?
var a = await UsersDataDB.HappendToMe
.AsQueryable()
.Select(x => x.MedDamages)
.GroupBy(x => x.Select(x => x.ProductId))
.Select(x => new
{
MedicineId = x.Key,
Damages = x.GroupBy(y => y.Select(z => z.DamageId))
.Select(c => new
{
DamageId = c.Key,
DamageType = c.GroupBy(d => d.Select(d => d.Damgetype))
.Select(e => new
{
Damgetype = e.Key,
HappendType = e.GroupBy(f => f.Select(f => f.HappendType))
.Select(g => new
{
HappendType = g.Key,
HappendCount = g.Count()
})
})
})
}).ToListAsync();
public IMongoCollection<HappendToMe> HappendToMe
{
get
{
return db.GetCollection<HappendToMe>("HappendToMe");
}
}
public class HappendToMe
{
[BsonId]
public ObjectId UserId { get; set; }
public List<Damage> MedDamages { get; set; }
}
public class Damage
{
public ObjectId ProductId { get; set; }
public ObjectId DamageId { get; set; }
public byte Damgetype { get; set; }
public byte HappendType { get; set; }
}