使用空值清空Linq查询

时间:2016-04-09 06:20:46

标签: c# entity-framework linq entity-framework-core

我的项目正在使用EF7-RC1。我的查询应返回匿名类型列表,但如果值为null,则结果为空。

我尝试使用以下方法解决此问题:

            var testQuery = (from com in db.Complaints
                select new
                {
                    ComplaintName = com.ComplaintName,
                    ProjectName = com.Project.ProjectName,
                    RemarkClient = com.RemarkClientNavigation != null ? com.RemarkClientNavigation.RemarkText : "n/a",
                    RemarkArchitect = com.RemarkArchitectNavigation != null ? com.RemarkArchitectNavigation.RemarkText : "n/a",
                }).ToList();

我也尝试过使用.DefaultIfEmpty()和一个空合并运算符,但查询结果仍然会返回空。

即使值为null,如何让我的查询返回结果?

0 个答案:

没有答案