Problem retrieving all child objects when there are grandchildren

Problem retrieving all child objects when there are grandchildren

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


awegele posted on Monday, November 27, 2006

I have created an object (Employee) that has children (Profiles) which in turn have children (Roles) and (Groups) using the CSLA 2.0 templates for Codesmith.  In the Profiles object, the fetch code looks like this:

private void Fetch(SafeDataReader dr)

{

RaiseListChangedEvents = false;

while(dr.Read())

this.Add(Profile.GetProfile(dr));

RaiseListChangedEvents = true;

}

In the Profile object, the fetch code calls the NextResult method to obtain the Roles and Groups but when control returns to the Profiles fetch method, the data reader is pointing to the groups resultset (which has already been looped thru) and thus the read returns false and the second profile record is not returned.

Is this a limitation of the CSLA model (ie only 2 levels) or is there a way to handle more than 2?

 

 

JoeFallon1 replied on Monday, November 27, 2006

The issue of fetching grandchild records has been discussed in great detail many times.

It is not a limitation of CSLA. There are many ways to do it. The Codesmith templates simply suggest one way to do it. If you do not like that method then you are free to override the implementation or simply write a new one.

Do a search of this forum for Grandchild and you should find some interesting reading including some details of the alternate methods.

Joe

malloc1024 replied on Monday, November 27, 2006

The answer to this question should be placed in the FAQ sticky because it is asked every week.  BTW, does anyone know where the FAQ sticky went? 

xal replied on Monday, November 27, 2006

We need better glue.

Andrés

ajj3085 replied on Monday, November 27, 2006

Indeed.

Here's the FAQ thread.  I can still edit it, but I can't make it sticky again.

Andy

xal replied on Monday, November 27, 2006

And by here you mean.... ??

Anyway, to address the original issue of the thread, the data reader will limit your ability to fill multiple levels. You have several options although the most common are:

I usually create a strongly typed dataset, fill it with one sp and navigate the relationships in order to fill the n-levels...
Using strongly typed is far easier than dynamic ds because you get a GetXYZRows() method for each of the relationships in the datarow, which makes the whole thing obscenely easy.
Things to keep in mind in this scenario:
Hope it helps!

Andrés

awegele replied on Tuesday, November 28, 2006

Thanks for the response.  I used lazy loading to resolve the immediate issue but I appreciate the variety of techniques identified by you and others and will use them in the future if I encounter the need.

awegele replied on Tuesday, November 28, 2006

Thanks for your response.  Smile [:)]

Copyright (c) Marimer LLC