更新时间:2022-03-17 09:46:27
使用Any
扩展名:
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
.在这种情况下,您要搜索两个元素,因此需要两个Any
调用.
Any
returns true
if there are any elements in the sequence that match the inner condition. In this case you're searching for two elements, so it takes two Any
calls.