I want to filter an IEnumerable<Product>
by its productId, but I want to have all comments for the products in my result.
public class Product
{
public int ProductId { get; set; }
public decimal Quantity { get; set; }
public List<ProductComments> Comments { get; set; }
}
For example: I have 3 Products
Id: 1, Quantity: 10, Comments: 2
Id: 1, Quantity: 20, Comments: 1
Id: 2, Quantity: 5, Comments: 1
What I what now is the follwing result:
Id: 1, Quantity: 30, Comments: 3 (I want the actual objects here, not just the count)
Id: 2, Quantity: 5, Comments: 1
How can I achieve this with LINQ? I think the way to go here is with GroupBy
.
Thanks!