如何使Linq查询从类别中获取所有Productpricediscounts?
public class ProductCategory
{
public List<Product> categoryProducts;
}
public class Product
{
public List<Productprice> productPrices;
}
public class Productprice
{
public List<Productpricediscount> priceDiscounts;
}
Run Code Online (Sandbox Code Playgroud)
我的查询必须看起来像:
categoryProducts.Select(p => p.productPrices).Select(x => x.?!?!
Run Code Online (Sandbox Code Playgroud)
问题是我会期待x.- intellisense建议priceDiscounts,但我得到"list" - 值(如:"Any","Select","Distinct"等等.)
Luk*_*keH 15
您需要使用SelectMany才能访问priceDiscounts:
var query = categoryProducts
.SelectMany(x => x.productPrices)
.SelectMany(y => y.priceDiscounts);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
18591 次 |
| 最近记录: |