[英]Adding a 3rd class in which 2 classes are subitems for linq query to end up displaying to json
[英]Data in Linq query not in join is not in output to json only those that are related in 2 classes are showing up
这个问题的基础来自于这个问题:
将2个类与添加数据组合在一起,其中1个表具有另一个表的集合列表,并希望使用linq进行显示
我在其中“解决”了问题。
但是,正如我在列表中添加新对象一样,现在此联接查询不会将其输出
reportData.Add(new ReportData() {ReportGroupId = 3, ReportGroupName = "Straggler", SortOrder = 3, Type = 1});
var reports = reportDefinition.GroupBy(r=>r.ReportGroupId);
var query = reportData.Join(reports, d => d.ReportGroupId, gr => gr.Key,
(r,gr) => new
{
r.ReportGroupName,
items = gr.ToList(),
r.ReportGroupId
});
这是dotNetFiddle https://dotnetfiddle.net/IIBFKG
为什么我添加到ReportData的项目没有显示? 这是Linq中的JOIN类型吗?
我认为链接的问题未正确回答。
看起来您只需要一个简单的Group Join :
var query =
from d in reportData
join r in reportDefinition on d.ReportGroupId equals r.ReportGroupId into items
select new
{
d.ReportGroupName,
items = items.ToList(),
d.ReportGroupId
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.