7
如果我有以下模型;LINQ嵌套在哪裏
public List<RecommendedProduct> recommendations
然後
public class RecommendedProduct
public List<Product> Products
然後將產物;
public class Product
public string Code
的建議列表有,作爲一個例子,在這10個項目。
每個建議項目中有兩種產品。
如何使用LINQ,我可以找到建議具有「A」和「B」產品代碼的產品的對象?如果存在序列中匹配的內條件的任何元件
var myProducts =
from rp in recommendations
where
cp.Products.Any(p => p.Product.Code == "A") &&
cp.Products.Any(p => p.Product.Code == "B")
select rp;
Any
返回true
:
+1精彩!謝謝@Aaronaught。 – griegs 2010-04-21 03:27:19