这是我的查询:
from forum in Forums
join post in Posts on forum equals post.Forum into postGroup
from p in postGroup
where p.ParentPostID==0
select new
{
forum.Title,
forum.ForumID,
LastPostTitle = p.Title,
LastPostAddedDate = p.AddedDate
}).OrderBy(o=>o.ForumID)
目前加入不是左加入,这意味着如果某个论坛没有属于它的帖子,则不会返回该帖子。
没有帖子的论坛必须返回帖子属性的 null(或默认)值。
UPDATE
结果集应该是这样的:
ForumId | ForumTitle | LastPostTitle | LastPostAddedDate
--------+------------+---------------+------------------
4 | Sport | blabla | 12/4/2010
4 | Sport | blabla | 15/4/2010
6 | Games | blabla | 1/5/2010
7 | Flame | |
var allforums = from f in context.Fora.Include("Posts")
select f;
该查询产生与以下相同的结果
var allForums = from f in context.Fora
select new ForumPosts
{
Forum = f,
Posts = context.Posts.Where(x=> x.ForumId == f.ForumId)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)