what is the best way to load grandchildren?

what is the best way to load grandchildren?

Old forum URL: forums.lhotka.net/forums/t/1784.aspx


MvdHoning posted on Friday, November 17, 2006

For my current project i hava an root object with chidlren and those children also have children (grandchildren to the root object). I want to initialize all from the root object. I have a SP that delivers all the data for that.
What is the best way to load all.

Looking on the forum i see:
Use a special SafeDataRowReader (i could not get it to work)
Use a dataset (seem to overhead to me, besides i have to rewrite datareader accees to dataset access)
 Load the grandchildren from the children( could cause a lot of SP trafic as for each child a SP is executed)
Merge children and grandchildren and seperate them again (yuck)
Are there even other ways of doing this?

Will the framework offer direct support for this (or does it already and i am unaware of that)?
Thanks for your ansers in advance.

david.wendelken replied on Friday, November 17, 2006

Project.cs in the sample ProjectTracker.Library contains an example of how to populate an object and its children with one call to a stored procedure.  Take a good look at the DataPortal_Fetch routine in it.

Once you understand that section of code, try extending it to handle grand-kids. 

hth!

MvdHoning replied on Friday, November 17, 2006

Loading children just goes fine, when trying to load grandchildren things do not anymore. I think the SafeDataReader cannot go back to the children level after reading a grandchild.

david.wendelken replied on Friday, November 17, 2006

SafeDataReader is an extension of DataReader, which if memory serves, is a one-way data access method.  So, by definition, it can't "go back".

Why not create a static method in your grand-kids collection that accepts the collection of kids and the datareader contents for the grand-kids.  It could parse out the data and add the grand-kids to the correct kid collection?

 

RealQuiet replied on Friday, November 17, 2006

You could retrieve your results into a dataset instead of a datareader and use that to populate your objects.  That is an option we have used in some instances, and it seems to work well.

Copyright (c) Marimer LLC