Handling Collections of Parent Objects With Children

Handling Collections of Parent Objects With Children

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


MadGerbil posted on Thursday, May 10, 2007

I need to load up a collection of parent objects, each of which has 2 collections of child objects.  I'm wanting to do this in the most efficient way possible and I could use some ideas/input.

One thought I have is to load up the parent objects and then have each parent object know how to cause itself to load child objects in separate queries to the database.  What I'm afraid of with this is that if the parent objects are being loaded by iterating through a datareader then I'll have to open a separate connection (and close it) for each collection of child objects.  If I load up 100 parent objects that would be a total of 201 connections being opened and closed.

I suppose I could preload a list of IDs and iterate through those IDs loading the individual parent object and subsequent child collections all at once on a per parent object basis.  I could do that with one connection but 100 separate hits to the database.

Ideas?

RockfordLhotka replied on Thursday, May 10, 2007

You may want to look at the DeepData sample from my website, where I illustrate how to use a top-down technique to do this in a pretty efficient manner. There's a DNR TV show about it too.

Copyright (c) Marimer LLC