LINQ to Entities和分组与多对多关联

Dan*_*Dan 0 linq-to-entities many-to-many entity-framework group-by

我在多对多关联中有一个产品和类别实体.我正在尝试显示每种产品的类别数量.到目前为止,我已经想出了这个:

Dim context = new Context()
Dim products = context.Products()
Dim productsByCategoryCount = From product In Products
 Group product By productId = product.productId Into productCount =  Count(product.cateogories.Count)
Run Code Online (Sandbox Code Playgroud)

查询执行但未显示正确的结果.我究竟做错了什么?

Ale*_*mes 5

像这样的查询应该这样做:

var results = from p in ctx.Products
              select new {Product = p, CategoryCount = p.Categories.Count}
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助

亚历克斯