2012-06-06 40 views
2
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(); 

如何預測構建器多標準?Linq PredicateBuilder多標準

回答

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