Table data:
Id_Org_hierarchy | Hierarchy_Name | Parent_Id_Org_hierarchy |
---|---|---|
1 | OGt | 0 |
2 | NHT | 1 |
3 | BATCH 1 | 2 |
3 | Voice | 1 |
I need result Like Below:
Batch1(NHT,OGT)
Details :
Id_Org_hierarchy column value is present in Parent_Id_Org_hierarchy and so on
its a tree struct format data.
can any one help me for this I have no idea how to achieve result.
Expecting this result Batch1(NHT,OGT)
2
Answers
Have a class structure representing the table rows, the solution would involve a recursive method to traverse the tree and build the result.
Here’s a basic solution:
Define your class:
Use LINQ and recursion:
Run the RunExample() method to see the result.
You will need to use multiple LINQ queries or entity framework calls that each finds a parent of the element, like this:
and then you can generate the string you wanted by putting
initial
‘sHierarchy_name
before the paranthesis and then wrap a paranthesis around the comma-separated concatenation of theHierarchy_name
values ofmyList
via