【发布时间】:2021-06-26 18:55:06
【问题描述】:
我需要按子实体对数据进行分组并获取子实体的总和。所以,我尝试了这个 linq:
context.Parent.Include(p => p.Child).GroupBy(p => p.Child.Type).Select(g => g.Sum(p => p.Child.Amount));
上面的 linq 会导致错误。但是,如果我要获得父实体的总和,它将起作用。
context.Parent.Include(p => p.Child).GroupBy(p => p.Child.Type).Select(g => g.Sum(p => p.Amount));
为什么我不能得到子实体的总和?
【问题讨论】:
-
错误是什么?什么版本的 EF Core:2.0 / 2.1 / 3.x / 5.x?
标签: c# .net linq asp.net-core entity-framework-core