如果第二个或第三个表为空,则LINQ Join不返回结果

 _i逗比_985 发布于 2023-02-12 12:39

我有3张桌子:

Module_Articles_Articles
Module_Articles_Categories
Module_Articles_Comments

我想在转发器中显示我的文章我的查询:

var articles =
                (from a in context.Module_Articles_Articles
                 join c in context.Module_Articles_Categories on a.CategoryID equals c.CategoryID
                 join co in context.Module_Articles_Comments on a.ArticleID equals co.ArticleID
                 where a.IsDraft == false
                 orderby a.ArticleID descending
                 select new
                 {
                     a.ArticleID,
                     a.ArticleTitle,
                     a.ArticleContent,
                     a.Image,
                     a.Sender,
                     a.SentDate,
                     a.Summary,
                     a.Likes,
                     a.Dislikes,
                     a.Tags,
                     a.PostMode,
                     c.CategoryID,
                     c.CategoryTitle,
                     AcceptedCommentsCount = 
                     (from com in context.Module_Articles_Comments where com.ArticleID == a.ArticleID && com.Status select com)
                     .Count(),
                     DeniedCommentsCount =
                     (from com in context.Module_Articles_Comments where com.ArticleID == a.ArticleID 
                          && com.Status == false select com)
                     .Count()
                 }).ToList();

但当Module_Articles_CategoriesModule_Articles_Comments为空时,我的查询什么也没有返回!我的代码是真的吗?如果不是我怎么能这样做?

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有