Fill a recursive data structure from a self-referencing database table

This question refers to http://www.matthidinger.com/archive/2009/02/08/asp.net-mvc-recursive-treeview-helper.aspx

Suppose I have a table that looks like this:

alt text
(source: matthidinger.com )

And I have a recursive data structure that looks like this:

public class TreeNode
{
    public TreeNode(){}
    public string NodeId { get; set; }
    public string ParentId { get; set; }
    public string Name { get; set; }
    public IEnumerable<TreeNode> Children { get; }
}

How do I populate this recursive data structure from a table using Linq?

: , , , ; , CTE. , Linq, Linq SQL DataContext . , , , ForEach ; .

.

+3
1

, - SQL CTE. LINQ2SQL / . . Linq - .

+1

Source: https://habr.com/ru/post/1726823/


All Articles