LINQ Group By and select collection

前端 未结 3 1100
隐瞒了意图╮
隐瞒了意图╮ 2021-01-30 09:58

I have this structure

Customer
 - has many Orders
  - has many OrderItems

I want to generate a list of CustomerItems via LINQ give

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-30 10:48

    you may also like this

    var Grp = Model.GroupBy(item => item.Order.Customer)
          .Select(group => new 
            { 
                 Customer = Model.First().Customer, 
                 CustomerId= group.Key,  
                 Orders= group.ToList() 
           })
          .ToList();
    

提交回复
热议问题