EF: Include with where clause
Several guys ask me if it’s possible to add a condition in the Include method and the answer is no.
However you can do an equivalent like this:
from cWithP in
(from c in context.Categories
select new
{
Category = c,
Products = from p in c.Products
where p.UnitPrice > 20
select p
}).AsEnumerable()
select cWithP.Category;
or the condensed equivalent:
context.Categories.Select(c => new { Category = c, Products = c.Products.Where(p => p.UnitPrice > 20) }).AsEnumerable().Select(cp => cp.Category);