Geeks With Blogs

News QTP and Stuff
Theo Moore Questions... Morphology? Longevity? Incept dates?

We were working on Parent-Child-Grandchild relationships in our CSLA project the other day. The client developer and I were discussing the best approach. We are trying to make as few trips to the database as possible (naturally), so we are using stored procedures that return several result sets. This is inline with the method normally used. This works great, as you can make a single trip and get all the parent-child data you need.

However, this paradigm falls down when grandchildren are introduced. The trouble is that if I have multiple children, it is problematic to get a return of the correct grandchildren for each child. Rocky says this is indeed the problem, and you are probably going to need to use separate stored procs for the grandchildren. You can, of course, group all of the grandchildren for a given child in one stored proc, of course. It's still another trip to the DB.

We were discussing this with a co-worker of mine also at the client site. We came up with an alternative: fetch the parent, fetch the children, and fetch the grandchildren in one stored proc as we do now. Load the parent, and load the children, as possible. However, to get the grandchildren, evaluate the result set of the grandchildren in the parent. Loop the result set and then add the grandchildren via the correct item in the child collection.

Admittedly, this isn't necessarily the best option, but it does allow the Parent-Child-Grandchild relationship to handled in DB trip. I am going to try and make time this week to build out a sample project that will use this. I am curious just how viable this approach really is.

Posted on Monday, June 11, 2007 12:50 AM | Back to top

Comments on this post: CSLA: Parent-Child-Grandchild relationships

# re: CSLA: Parent-Child-Grandchild relationships
Requesting Gravatar...
This is definitely do-able, and not a bad approach, in my opinion. We've done it on one of our projects, and it worked really well. It really cut down the database retrieval time! (Right now, we're trying to take it to the next level... Populating great-grand-child objects. Shouldn't be too tough. However, the ultimate goal is to be able to make it generic enough to be able to handle an unlimited number of generations without having to write a ton of code. Should be fun.)
Left by Jamie Foster on Jun 14, 2007 12:58 PM

Comments have been closed on this topic.
Copyright © Theo Moore | Powered by: