【发布时间】:2021-05-22 16:30:57
【问题描述】:
所以我有一张票的列表,我想按客户对它们进行分组,然后将这些票的票务操作的所有价格相加。
query2 = query.GroupBy(x => new {x.Customer.Id, x.Customer.BusinessName}).Select(x => new TicketStatisticsRow {
Field = x.Key.BusinessName,
Tickets = x.Count(),
TotalPrice = x.Sum(t => t.TicketOperations.Sum(to => to.Price))
});
除了尝试 TotalPrice 的总和之外,我尝试了x.SelectMany(e => e.TicketOperations).Sum(x=> x.Price) 这两种解决方案都无法在本地评估。在这种情况下,最好的方法是什么?
机票等级参考:
public class Ticket {
public Customer Customer { get; set; }
public ICollection<TicketOperation> TicketOperations { get; set; }
public class TicketOperation {
public decimal Price { get; set; }
}
}
【问题讨论】:
标签: entity-framework asp.net-core entity-framework-core asp.net-core-3.1