Question

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(); 

How to PredicateBuilder multi-criteria?

Was it helpful?

Solution

Something like the following:

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)

You can read more about PredicateBuilder here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top