【发布时间】:2011-02-17 07:41:47
【问题描述】:
在How To Count Associated Entities using Where In Entity Framework 我得到这个查询
但是当我访问 queryResult[0].post.Category 或 queryResult[0].post.Tags 时,它总是为空,因为我没有使用 Include。
包括不使用 Projection,正如微软在此处的最后一项所说:http://msdn.microsoft.com/en-us/library/bb896317.aspx
var queryResult = (from post in posts
join comment in comments.Where(x=> x.IsPublic) on post.Id equals comment.Post.Id into g
select new
{
post,
post.Author,
post.Tags,
post.Categories,
Count = g.Count()
})
如何在同一查询中获取计数,并包含与标签和类别的关系?
为什么 EF 关系修复在这里不起作用?
【问题讨论】:
-
它应该可以正常工作。也许您的模型类有问题。你可以在这个问题中添加 EF Code First 代码吗?
-
我做了一些研究,这是预期的行为。关系修复不适用于多对多
-
有一个有效答案的类似问题:stackoverflow.com/questions/7167547/…
标签: c# linq entity-framework entity-framework-4 linq-to-entities