【发布时间】:2014-11-19 04:14:59
【问题描述】:
我有以下 SQL 表数据:
可视化树应该如下所示:
要获得我正在使用的最顶级节点:
var parentNodes = data
.Where(i => i.AncestorId == i.DescedantId &&
(data.Count(d => d.DescedantId == i.DescedantId) == 1))
.ToList();
关于如何构建一个循环遍历结构然后构建树形对象的函数的任何线索?
我的树形对象类是:
public class ProfitCenterRoot
{
public List<ProfitCenterItem> Data { get; set; }
}
public class ProfitCenterItem
{
public int AncestorId { get; set; }
public int DescendantId { get; set; }
public string Text { get; set; }
public bool Leaf { get; set; }
// These are the child items
public List<ProfitCenterItem> Data { get; set; }
}
【问题讨论】:
-
我认为你应该在这里使用
recusrive method。 -
我该如何实现?
标签: c# linq linq-to-objects