Constructing a tree structure from table?

c# entity-framework

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:

This is my table structure:

作者: maddy23285 发布者: 2017 年 12 月 27 日
32x32