【发布时间】:2020-11-18 15:33:54
【问题描述】:
我有以下两种型号
public class DepotDeptMapModel
{
public string id { get; set; }
public string title { get; set; }
public List<DeptModel> subs { get; set; }
}
public class DeptModel
{
public string id { get; set; }
public string title { get; set; }
}
我正在使用给定的 LINQ 查询来获取结果
var list = goContext.goDepartmentWorkTime.
GroupBy(d => new { d.DepotID, d.Depot.DepotName })
.Select(g => new
{
id = g.Key.DepotID,
title = g.Key.DepotName,
subs = g.Select(dd => new
{
id = dd.DepotID + "." + dd.DepartmentID,
title = dd.Depot.DepotNo + "." + dd.Department.DepartmentName
})
});
是否可以将查询结果放入列表模型中
List<DepotDeptMapModel> deptList
任何帮助将不胜感激
【问题讨论】:
-
当然。您所要做的就是使用更多
.Select()调用,就像您在代码中所做的那样。你能解释一下你到底卡在哪里了吗?
标签: linq asp.net-core ienumerable