Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

hierachical table to c# class

var lookup = dataTable.Rows.Cast<DataRow>().ToLookup(x => x.Field<int>("ParentId"));

Func<int, Item[]> build = null;
build = n =>
    lookup[n]
        .Select(dr => new Item()
            {
                Id = dr.Field<int>("Id"),
                Name = dr.Field<string>("Name"),
                Children = build(dr.Field<int>("Id")),
            })
            .ToArray();

var items = build(0);
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #hierachical #table #class
ADD COMMENT
Topic
Name
9+8 =