I have the following expression (simplified):
from p in Providers
select new { p.Name, p.Accounts.Count(a => a.State == 2) };
This works fine, but now I want to create a reusable expression like so:
Expression<Func<Account, bool>> MyPredicate() { return a => a.State == 2; }
and use it like so:
from p in Providers select new { p.Name, p.Accounts.Count(MyPredicate()) }
This unfortunately doesn't work because the navigation property (Accounts) is an IList or ICollection in EF. What's the pattern here? Happy to change things around a little, but note that I'm not after dynamic expressions just reusable ones.