![](/img/trans.png)
[英]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.