-1

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?

dim
  • 59
  • 11
Coder
  • 181
  • 1
  • 1
  • 5
  • I'm not sure your question contains enough information to form an answer, and if it did I'm not sure it would be on topic / within scope for stackoverflow – Caius Jard Dec 27 '17 at 17:04

1 Answers1

0

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
  • 738
  • 6
  • 16
  • In my case I am passing RootTreeNode with Tag=0, so at first execution it will get all parent node or main category and add them under root node. – maddy23285 Dec 27 '17 at 17:21