I need to filter only the visibles products from a category, but it's not working.
Category category = db.Categories
.Include(c => c.Products.Where(p => p.IsVisible))
.First(c => c.CategoryID == id);
Error:
The Include path expression must refer to a navigation property defined on the type. Use dotted paths for reference navigation properties and the Select operator for collection navigation properties.
UPDATE
var result = (from c in db.Categories
where c.CategoryID == id
select new
{
CategoryID = c.CategoryID,
Description = c.Description,
Products = (from p in db.Products
where p.IsVisible
&& p.CategoryID == c.CategoryID
orderby p.DateSent descending
select p)
}).FirstOrDefault();
but now i need to cast the anonymousType to Category