Когда я пытаюсь перебрать этот метод SQL to LINQ, я получаю только все строки forum_category. Что я действительно хочу сделать, так это получить все строки из forum_category, а также вернуть все форумы, соответствующие идентификатору категории, вот ожидаемый результат:
FORUM_CATEGORY (categoryid, categorytitle)
- FORUM (forumid, forumtitle, forumdescrition) -> (latest topic => topicid, topictitle) -> (latest post on that latest topic => postid, postadded, username) -> total topic count, total post count in this forum only
- FORUM (forumid, forumtitle, forumdescrition) -> (latest topic => topicid, topictitle) -> (latest post on that latest topic => postid, postadded, username) -> total topic count, total post count in this forum only
- FORUM (forumid, forumtitle, forumdescrition) -> (latest topic => topicid, topictitle) -> (latest post on that latest topic => postid, postadded, username) -> total topic count, total post count in this forum only
FORUM_CATEGORY
- FORUM [...]
- FORUM [...]
- FORUM [...]
Вы поняли ...
-
Вот что я сейчас получаю:
FORUM_CATEGORY
- FORUM (forumid, forumtitle, forumdescrition) -> (latest topic => topicid, topictitle) -> (latest post on that latest topic => postid, postadded, username) -> total topic count, total post count in this forum only
FORUM_CATEGORY
- FORUM (forumid, forumtitle, forumdescrition) -> (latest topic => topicid, topictitle) -> (latest post on that latest topic => postid, postadded, username) -> total topic count, total post count in this forum only
То есть только один форум для каждой категории форумов.
Вот код LINQ:
var forum = (from c in context.forum_category
join f in context.forum on c.id equals f.categoryid
join t in context.forum_topic on f.id equals t.forumid
join tc in context.forum_topic on f.id equals tc.forumid into tcount
join p in context.forum_posts on t.id equals p.topicid
join pc in context.forum_posts on t.id equals pc.topicid into pcount
join u in context.users on p.userid equals u.id
orderby p.added descending
select new ForumIndexModel
{
CategoryId = c.id,
CategoryTitle = c.title,
ForumId = f.id,
ForumTitle = f.title,
ForumDescription = f.description,
TopicId = t.id,
TopicTitle = t.title,
PostId = p.id,
PostAdded = p.added,
Username = u.username,
TopicCount = tcount.Count(),
PostCount = pcount.Count()
}).ToList();
return View(forum);
Это лишь один из примеров различных подходов, которые я использовал.
РЕДАКТИРОВАТЬ: уточнил, что я хочу более конкретно.