2
我使用下面的表達式:實體框架4.1 - 選擇
ProductRepository.Query.Include(Function(x) x.ChildProducts.Select(Function(y) y.PriceTiers.Where(Function(z) z.IsActive))).Where(Function(x) x.Categories.Any(Function(y) y.ID = 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.
如果我刪除此:
.Where(Function(z) z.IsActive)
它工作正常,但我需要過濾不活動的價格層。
任何想法?
更新
這裏是我的解決方案:
Public Function GetProductsByCategoryID(ID As Integer) As System.Collections.Generic.IEnumerable(Of Core.Entities.Product) Implements Core.Interfaces.IProductService.GetProductsByCategoryID
Dim Col = ProductRepository.Query.Where(Function(x) x.Display AndAlso x.Categories.Any(Function(y) y.ID = ID)) _
.Select(Function(x) New With { _
.Product = x,
.ChildProducts = x.ChildProducts.Where(Function(y) y.Display).Select(Function(y) New With { _
.ChildProduct = y,
.PriceTiers = y.PriceTiers.Where(Function(z) z.IsActive)
})
}).ToList.Select(Function(x) x.Product)
Return Col
End Function
@Lad - 謝謝! – Sam 2011-04-14 15:41:02
@Lad - 所以這假設你有一個產品正確行事?如果是這樣,你將如何做到這一點與產品集合? – Sam 2011-04-14 16:01:07
它不適用於收集。您必須改用投影來使用自定義查詢。 – 2011-04-14 16:16:47