I have a self-referenced table like below.
key | parent | Description |
---|---|---|
A | NULL | |
B | A | |
C | B | |
D | C |
And initially having 1 Key value. Using this key value, I need to find all the child nodes recursively and update the description field.
This table contains around 27 thousand records with multiple levels of hierarchy.
I'm trying with the below code to update the description.
Private Sub ChangeDescriptionChildRows(ByRef row As DataRow,
ByRef table As DataTable)
UpdateDescription(row) 'Already having Root node
For Each childRow As DataRow In table.Select("parent=" & row("key"))
UpdateDescription(childRow, table) 'Recursion
Next
End Sub
Private Sub UpdateDescription(ByRef row As System.Data.DataRow)
Dim description As String = ""
If row("key") = "A" Then
description = "This is Root Node"
ElseIf row("Key") = "B" Then
description = "Something"
End If
row("description") = description
End Sub
It's taking a lot of time to update the table.
Is there any better way to update the table using plinq/parallel.foreach ?