I have a table (let's say DataTable for this example) which has hierarchy records ( id,ParentId,IsEmergency) :
ParentId=0
means root.
So we have this :
0
|
+--- 4706606
|
+--- 4706605
|
+--- 4666762
|
+--- 4668461
|
+--- 4706607
I'm after displaying only the those records who has parentId=0
But I want to add another logical column which states "this parent has IsEmergency=true
in one of it's childs/sub childs
So I'm after
id parentId hasEmergencyInOneOfItsChild
-------------------------------------------------------
4706606 0 false
4706605 0 false
4666762 0 true
Question:
How can I achieve it via recursive linq ?
For convenience I created this Datatable :
DataTable dt = new DataTable("myTable");
dt.Columns.Add("id", typeof (int));
dt.Columns.Add("parentId", typeof (int));
dt.Columns.Add("isEmergency", typeof (bool));
DataRow row = dt.NewRow();
row["id"] =4706606;
row["parentId"] = 0;
row["isEmergency"] =false;
dt.Rows.Add(row);
row = dt.NewRow();
row["id"] =4706605;
row["parentId"] = 0;
row["isEmergency"] = false;
dt.Rows.Add(row);
row = dt.NewRow();
row["id"] =4666762;
row["parentId"] = 0;
row["isEmergency"] =false;
dt.Rows.Add(row);
row = dt.NewRow();
row["id"] =4668461;
row["parentId"] = 4666762;
row["isEmergency"] = false;
dt.Rows.Add(row);
row = dt.NewRow();
row["id"] =4706607;
row["parentId"] = 4668461;
row["isEmergency"] = true;
dt.Rows.Add(row);
I've tried something but it is pretty nasty and not efficient