List<Product> Prs = data.Products
.Where(x=> x.ProductColors
.Where(y=> y.Color=="blue")
.Select(z=> z.ProductID)
.Contains(x.ID) && x.ProductColors
.Where(y=> y.Color== "red")
.Select(z=> z.ProductID)
.Contains(x.ID))
.ToList();
如何PredicateBuilder多标准?
答案 0 :(得分:3)
如下所示:
var inner = PredicateBuilder.False<Product>();
inner = inner.Or (p => p.Description.Contains ("foo"));
inner = inner.Or (p => p.Description.Contains ("far"));
var outer = PredicateBuilder.True<Product>();
outer = outer.And (p => p.Price > 100);
outer = outer.And (p => p.Price < 1000);
outer = outer.And (inner);
var results = data.Products.AsExpandable().Where(outer)
您可以阅读有关PredicateBuilder here
的更多信息