LINQ Select from sub-list

后端 未结 2 2033
情话喂你
情话喂你 2021-01-06 01:19

How can I make a Linq query to grab ALL Productpricediscounts from a category?

public class ProductCategory
{
    public List categoryProducts         


        
2条回答
  •  太阳男子
    2021-01-06 01:35

    You need Enumerable.SelectMany

    var result = categoryProducts.SelectMany(x => x.productPrices)
                 .SelectMany(x => x.priceDiscounts);
    

提交回复
热议问题