[英]entity framework - inner join to left join
美好的一天! 我需要在我的查询中将左连接转换为连接-
var query = (from sections in context.Sections
join themes in context.Themes on sections.SectionId equals themes.SectionId
join comments in context.Comments on themes.ThemeId equals comments.ThemeId
select new { sections.SectionId, sections.SectionTitle, themes.ThemeId, comments.CommentId } into x
group x by new { x.SectionId, x.SectionTitle } into g
select new SectionInfo
{
SectionId = g.Key.SectionId,
SectionTitle = g.Key.SectionTitle,
ThemeCount = g.Select(s => s.ThemeId).Count(),
CommentCount = g.Select(s => s.CommentId).Count()
}).ToList();
-请,我不知道(
您需要使用DefaultIfEmpty
一种方式是这样的:
from themes in context.Themes.Where(x => sections.SectionId == x.SectionId)
.DefaultIfEmpty()
替代方式
join themes in context.Themes on sections.SectionId equals themes.SectionId into themesGroup
from themes in themesGroup.DefaultIfEmpty()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.