2016-11-16 62 views
0

我需要獲得封面圖片的產品。但是當我加pic => pic.IsCover這是拋出異常。否則沒有問題。我如何解決它?流利的Api包括哪裏條款

錯誤:

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. Parametre adı: path

感謝所有

_db.ProdSmartSorts 
    .Where(x => catIds.Contains((int)x.Product.CategoryId)) 
    .OrderBy(x => x.ProdSmartId) 
    .Select(x => x.Product) 
    .Include(p => p.Pictures.Where(pic => pic.IsCover)) 
    .Skip(prodCount * (pageNumber - 1)) 
    .Take(prodCount) 
    .ToList(); 
+0

嘗試使用SelectMany而不是Select –

回答

0

在DbSet工作後直接調用.Include()方法嗎?即

_db.ProdSmartSorts 
.Include(p => p.Pictures) 
.Where(x => catIds.Contains((int)x.Product.CategoryId)) 
.OrderBy(x => x.ProdSmartId) 
.Select(x => x.Product) 
.Skip(prodCount * (pageNumber - 1)) 
.Take(prodCount) 
.ToList(); 

我認爲Include方法只適用於dbContext中的DbSet對象。如果您嘗試將其放在鏈條的更下方,則只能根據具體情況爲IQueryable或IEnumerable對象提供方法。

此外,據我所知,您不能像您嘗試的那樣使用包含功能來過濾。所以你將不得不加載所有圖像相關的圖片實體。

編輯:抱歉 - 剛纔意識到這個問題是特別要求過濾Include()方法。請忽略。