Search
 
SCRIPT & CODE EXAMPLE
 

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);
Comment

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);
Comment

PREVIOUS NEXT
Code Example
Csharp :: Query Parent-GrandChild collection 
Csharp :: whining 
Csharp :: get 24 hour time in c# 
Csharp :: Custom Encrypted String Type 
Csharp :: how to get scene color to work with urp unity 
Csharp :: générer un nombre aléatoire en c# 
Csharp :: how to change something in the window using a thread wpf 
Csharp :: Deserialize a Dictionary 
Csharp :: take out substring from string 
Csharp :: .net framework method 
Csharp :: allelrt box wpf 
Csharp :: How to execute a script after the c# function executed 
Csharp :: virtual list entity framework 
Csharp :: convert relative path to physical path c# 
Csharp :: string with starting zero to int c# 
Csharp :: c# read csv file save to database dynamically 
Csharp :: c# core deploy on gcp with powershell 
Csharp :: ado .net nullable int datareader 
Csharp :: check null type 
Csharp :: cefsharp not passing keydown to form 
Csharp :: in clause db2 c# 
Csharp :: disable quickedit c# 
Csharp :: Razor switch statement 
Csharp :: accord.io read .mat file 
Csharp :: google script get font color 
Csharp :: c# initialize event 
Csharp :: c# sort a list of objects 
Csharp :: how to execute a function in every object of list c# 
Csharp :: recursively fing root of tree 
Csharp :: unity enable hdr picker 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =