最佳答案
我有这种结构
Customer
- has many Orders
- has many OrderItems
我想通过给定 OrderItems
的子集的 LINQ 生成一个 CustomerItems
列表:
List of new { Customer, List<OrderItem> Items }
它是顾客从商品子集中订购的所有商品的分组
我怎样才能使用 LINQ 回溯跟踪通过订单和分组的客户生成这个对象?
到目前为止,我还在
items
.GroupBy(i => i, i => i.Order.Customer, (i, customer) => new {customer, i})
但这显然不是一个名单。我想我需要一个 SelectMany 在那里的地方,但可以做一些指针。