LINQ Group By and select collection

前端 未结 3 1169
隐瞒了意图╮
隐瞒了意图╮ 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:36

    you can achive it with group join

    var result = (from c in Customers
              join oi in OrderItems on c.Id equals oi.Order.Customer.Id into g
              Select new { customer = c, orderItems = g});
    

    c is Customer and g is the customers order items.

提交回复
热议问题