Constructing a tree structure from table?
39 观看
1回复
44 作者的声誉
I have a similar requirement as this question at: What is the most efficient/elegant way to parse a flat table into a tree?
In my case, the table can contain potentially a millions of row, the depth of the node structure to the root may be around 5 to 6, but the breadth of the nodes could be huge,
I am using entity framework C#, is there a fast and efficient algorithm by which we can figure out the structure via entity?
作者: Coder 的来源 发布者: 2017 年 12 月 27 日回应 1
0像
315 作者的声誉
If you have DataTable, you can try something like this (recursive function):
private void FillTree(TreeNode pnode,DataTable data)
{
DataRow[] cnodes = data.Select("catparent=" + pnode.Tag.ToString());
foreach (DataRow crow in cnodes)
{
TreeNode ctn = new TreeNode(crow["catname"].ToString());
ctn.Name = "Cat" + crow["cat_id"].ToString();
ctn.Tag = crow["cat_id"].ToString();
pnode.Nodes.Add(ctn);
FillTree(ctn, data);
}
}
This is my table structure:
作者: maddy23285 发布者: 2017 年 12 月 27 日来自类别的问题 :
- c# Convert Decimal to Double?
- c# 如何计算C#中某人的年龄?
- c# 你如何按价值排序字典?
- c# Java和C#中的int和Integer有什么区别?
- c# 如何从Type创建新的对象实例
- c# 在.NET中使用后将对象设置为Null / Nothing
- c# 将整数转换为书面数字
- c# 如何动态评估C#代码?
- c# 如何使按钮看起来像被按下一样?
- c# 在C#中,为什么List <string>对象不能存储在List <object>变量中
- entity-framework 实体框架与LINQ to SQL
- entity-framework 您可以在Oracle中使用Microsoft Entity Framework吗?
- entity-framework 实体框架的多个后端
- entity-framework 如果不支持Contains,如何在LINQ to Entities(实体框架)中执行SQL样式的“IN”语句?
- entity-framework 实体框架.Include()另一个Navigation属性的导航
- entity-framework 如何仅将Linq中DateTime类型中的没有日期的Date与带有实体框架的SQL进行比较?
- entity-framework 将DateTime属性的默认值设置为System.ComponentModel内的DateTime.Now默认值Attrbute
- entity-framework 使用带有Entity Framework的(Sql Server)xml列
- entity-framework 实体框架错误 - “EntityContainer名称必须是唯一的”
- entity-framework 如何查看实体框架生成的SQL?