问题描述
此问题基于
此答案DID可以正常工作
in which this answer DID work fine
但是,我要添加一个第三类,我想将其归类为项目"
However, I'm adding a 3rd class that i want to group into "items"
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
};
新更新的dotnetfiddle https://dotnetfiddle.net/IIBFKG
New updated dotnetfiddle https://dotnetfiddle.net/IIBFKG
我如何添加CustomReportDefinition类以使其显示在项目或ReportData中?
How do I ADD in CustomReportDefinition class to get displayed in the items or ReportData?
推荐答案
实际上,您可以使用完全相同的模式根据需要添加任意多个相似的类:
Actually you can add as many similar classes as you wish using exactly the same pattern:
var query = from d in reportData
join r in reportDefinition on d.ReportGroupId equals r.ReportGroupId into items
join cr in customReportDefinition on d.ReportGroupId equals cr.ReportGroupId into customItems
select new
{
d.ReportGroupName,
items = items.ToList(),
customItems = customItems.ToList(),
d.ReportGroupId
};
更新:根据您的评论,您似乎希望合并items
和customItems
.查看以下各项是否对您有用:
UPDATE: Base on your comments, looks like you want to consolidate items
and customItems
. See if the following works for you:
var query = from d in reportData
join r in reportDefinition on d.ReportGroupId equals r.ReportGroupId into items
join cr in customReportDefinition on d.ReportGroupId equals cr.ReportGroupId into customItems
select new
{
d.ReportGroupName,
items = items.Select(r => new
{
r.Id, r.ReportGroupNameDef, r.SortOrder, r.ReportGroupId, r.Type
}).Concat(customItems.Select(cr => new
{
cr.Id, cr.ReportGroupNameDef, cr.SortOrder, cr.ReportGroupId, cr.Type
})).ToList(),
d.ReportGroupId
};
这篇关于添加第三个类,其中2个类是linq查询的子项,最终显示到json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!