I have a parent child table of Evolution progress in my db
EvolutionID ParentID otherFields
A0 NULL *
A1 A0 *
A2 A1 *
B0 NULL *
B1 B0 *
B2 B1 *
I need to display in my asp.net-mvc page like this:
-------------------------------------
| A0 | A1 | A2 |
| field.* | fields.* | fields.* |
-------------------------------------
| B0 | B1 | B2 |
| field.* | fields.* | fields.* |
-------------------------------------
What I can do now is first read the Evolutions with parentID = null
A0
B0
and then create a list for each one using a function to bring the childs from db:
List<Evolution> A0 = GetEvolutionListFor ('A0');
List<Evolution> B0 = GetEvolutionListFor ('B0');
Finally pass the List in a ViewBag
List<List<Evolution>> EvolutionList = New List<List<Evolution>>() {
A0, A1 };
ViewBag.Evolutions = EvolutionList ;
I dont have problem with the display, I can create a Evolution template to render the object in each table cell.
My problem is what is the best way to bring the data to the model.
Right now is one query to bring the root nodes and one more query for each node to bring the list.
Should I retrive all the rows at once and build the lists on my client app. Or is there a way I can retrive that data direct from database?