Converting a flat data structure to an Object hierarchy using C #

I have the following flat data structure.

ParentAttributeId AttributeId  List
----------------- -----------  ------
NULL              29          TestcaseCollection
29                30              EnclosureLeakageDielectricStrengthTest
30                31                  DeviceID
30                32                  ScannerOneLowChannel
30                33                  ScannerTwoLowChannel
29                34              EnclosureLeakageLeakageCurrentTest
34                35                  DeviceID
34                36                  ScannerOneLowChannel
34                37                  ScannerTwoLowChannel
29                38              PatientCircuitLeakageTest
38                39                  DeviceID
38                40                  ScannerOneLowChannel
38                41                  ScannerTwoLowChannel
29                42              SIPSOPDielectricStrengthTest
42                44                  ScannerOneHighChannel
42                45                  ScannerOneLowChannel
42                46                  ScannerTwoHighChannel
42                47                  ScannerTwoLowChannel
29                48              SIPSOPLeakageCurrentTest
48                49                  ScannerOneHighChannel
48                50                  ScannerOneLowChannel
48                51                  ScannerTwoHighChannel
48                52                  ScannerTwoLowChannel

I need to convert the above flat data structure to a hierarchical structure of objects, as shown below. So my object looks like the List column above. I am using SQL Stored Proc to get the above data. I am using C #.

Object hierarchy

29
  |
  30 
   |  31
   |  32
   |  33
   |   
  34
   |  35
   |  36
    |37
  38

Any help would be greatly appreciated.

Relations Niju

+3
source share
1 answer

Have you watched AutoMapper ?

Not sure if this is what you need, but this is what I often use to convert from one format to an object model.

LINQ , , .

, - , ;

List {....

new , .

, , , .

.

0

All Articles