Having IEnumerable<Order> orders
, how to get a Dictionary<string, IEnumerable<Order>>
using Linq, where the key is Order.CustomerName
mapped to a IEnumerable
of customer's orders.
orders.ToDictionary(order => order.CustomerName)
is not going to work right away, since there could be multiple orders that could have the same CustomerName.
Solution: orders.ToLookup(order => order.CustomerName);