0
我需要一些幫助從EF 4.1查詢獲取一些數據。EF LINQ查詢 - 多對多
我有一個Products
表和Categories
表,它們之間有多對多的關係。
我需要通過ID選擇產品並在其中包含與其關聯的類別。
我想出了這一點:
Public Function GetProductByID(ID As Integer) As Core.Entities.Product Implements Core.Interfaces.IProductService.GetProductByID
Dim p = ProductRepository.Query.Single(Function(x) x.ID = ID)
p.Categories = CategoryRepository.Query.Where(Function(x) x.Products.Any(Function(y) y.ID = ID)).ToList
Return p
End Function
我肯定有一個更好的辦法!