I am trying to do an OR. I thought you could do this with Predicate, so I tried this
var products = ctx.Products.Where(x => .....);
var predicate = PredicateBuilder.False<Product>();
foreach (Category categ in categs)
predicate = predicate.Or(p => p.Categories.Select(c => c.Id).Contains(categ.Id)
|| p.Categories.Select(c => c.Category1.Id).Contains(categ.Id)
|| p.Categories.Select(c => c.Category1.Category1.Id).Contains(categ.Id));
products = products.Where(predicate);
but it gives me this error
System.NotSupportedException: The LINQ expression node type ‘Invoke’ is not supported in LINQ to Entities.
Could someone please help me solve this? Thanks in advanced.
A Product can have one or more Category.
Category may have a “parent category” called Category1. Those long 3 lines above is to select products under a category or its child categories.
I googled and found LinqKit, but I want to avoid adding a 3rd party just for this. But if I have to use LinqKit, is it easy to install?
I think this works
IsUnderCategory is an extension