I’m trying to group orders by customer id then project the orders returned (by customer) into a List. Trying to figure out how I would do this?
List<OrderGroup> set = OrderRepository.GetAllOrders
.GroupBy(x => x.CustomerId).Select(result => new OrderGroup
{
Orders = ???? //should be all orders from one customer.
}).ToList();
The
resultis anIGrouping<TKey, T>, which is itself anIEnumerable<T>, so you can do:(Note that this assumes
Ordersis assignable from aList<Order>.)