我需要僅篩選類別中的可見產品,但它不起作用。Lambda表達式過濾包含與實體框架相關的數據
Category category = db.Categories
.Include(c => c.Products.Where(p => p.IsVisible))
.First(c => c.CategoryID == id);
錯誤:
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();
,但現在我需要的anonymousType投類別
http://stackoverflow.com/questions/10035261/include-using- lambda表達式 –