I have a classic Order -> Order Row scenario something like this:
public class Order
{
public int Id { get; set; }
public string Name { get; set; }
public List<OrderRow> OrderRows { get; set; }
}
public class OrderRow
{
public int Id { get; set; }
public int ProductId { get; set; }
public int Amount { get; set; }
}
and a List<Order>. From that list of orders I want to get a list of all the unique ProductIds.
I solved it like this:
var orders = new List<Order>();
// TODO get the orders from DB
var products = new Dictionary<int,int>();
orders.ForEach(order => order.OrderRows.ForEach(row => products[row.ProductId]=row.ProductId));
but I got questions about my use of Dictionary and why I didn't use LINQs GroupBy and also comments that it wasn't very clear how it worked. I think the solution is fine but the comments made me want to try to solve it in LINQ but for some reason I hit a brick wall trying.
How do I get a list of unique products ids from a list of orders with LINQ here?