I have the following query in LINQ to Entities:
var query = from p in db.Products where p.Price > 10M select p;
At this point, the request was not completed, and I want to write a request that returns true / false based on some conditions:
return query.Any(p => p.IsInStock && (p.Category == "Beverage" || p.Category == "Other"));
This works great; however, I would like to get some reuse from my code. I have many methods that need to be filtered if the category is a drink or another, so I tried to create a delegate:
Func<Product, bool> eligibleForDiscount = (product) => product.Category == "Beverage" || product.Category == "Other";
I would like to replace the inline check with a delegate:
return query.Any(p => p.IsInStock && eligibleForDiscount(p));
This gives me an error saying LINQ to Entities does not support Invoke. Why can't I replace the inline code for such a delegate, and is there any way to reuse it in another way?
source share