我如何进行 Linq 查询以从一个类别中获取所有 Productpricediscounts?
public class ProductCategory
{
public List<Product> categoryProducts;
}
public class Product
{
public List<Productprice> productPrices;
}
public class Productprice
{
public List<Productpricediscount> priceDiscounts;
}
我的查询必须类似于:
categoryProducts.Select(p => p.productPrices).Select(x => x.?!?!
问题是我会预料到 x。 - 智能感知建议 priceDiscounts
,但我得到“列表”值(例如:“Any”、“Select”、“Distinct”等。)
最佳答案
您需要使用 SelectMany
为了访问 priceDiscounts
:
var query = categoryProducts
.SelectMany(x => x.productPrices)
.SelectMany(y => y.priceDiscounts);
关于c# - LINQ 从子列表中选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1679933/