Hi,
I am creating a group of nested objects that relate to one parent object and am a bit stuck in the process (I am using CSLA.NET CodeSmith templates from the CSLAContrib project).
Ok so I have one root object ROOTOBJECT,
It has 1 child object CHILD1 and a collection of child1 is a member of ROOTOBJECT
ie CHILD1COLLECTION is a member of ROOTOBJECT
The Child objects have a collection of sub-child objects
SUBCHILD1_COLLECTION is CHILD1's collection
Ok ROOTOBJECT has a ROOT_SelectProcedure that selects the root object and then calls CHILD1_SelectByRootId that selects all Child1 objects that have a foreign key to the ROOTID field. The CHILD1_SelectByRootId also calls SUBCHILD1_SelectByChild1ID to get all sub-child objects for Child1.
Ok now in the code for ROOTOBJECT1, it calls FetchObject which gets a datareader, reads its own fields, calls GetnextResultSet and passes the datareader to CHILD1COLLECTION, which loops to read from the datareader and then calls the constructor of the CHILD1 object, passing in the datareader. CHILD1 builds its fields from the datareader and then calls GetNextResultSet to build its CHILD1COLLECTION.
Here is where the problem is because CHILD1COLLECTION is still reading from the datareader in a while loop and as soon as GetNextResultSet is called, the loop breaks and I only get 1 item for CHILD1COLLECTION.
Surely, there must be a better way to do this. I want to work with the CSLA.NET templates and not change its core pattern by much. Does anyone have a best practice on how nested child collections can be fetched?
Many Thanks,
Shailen Sukul
Hi Shailen,
Rocky wrote a demo called DeepData that shows an example of loading grandchild objects using a DataReader. The code can be downloaded from http://www.lhotka.net/Article.aspx?area=11&id=65c98c98-f0e0-477d-b45b-7a1e7d5768ee
Cheers,
Herman
This topic has been discussed many times.
Try searching the FAQ and the forum for "grandchild".
Thank you McManus and JoeFallon for your replies.
I shall investigate both options and update this thread with my findings.
:)
Shailen
I have decided to create a variant of CSLA Contrib that would allow:
1. Multiple nested levels
2. Use of DAAB
See http://shailensukul.blogspot.com/2007/07/start-new-branch-of-cslanet-template.html
Thanks
Shailen Sukul
Copyright (c) Marimer LLC