LINQ Select from sub-list

后端 未结 2 2030
情话喂你
情话喂你 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:36

    You'll need to use SelectMany in order to access priceDiscounts:

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

提交回复
热议问题