CodeSmith And GrandChild ?

CodeSmith And GrandChild ?

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


JoOfMetL posted on Friday, September 01, 2006

Hello,

Do templates propose a solution to solve the problem of  oading GrandChild ?

Thank you

Brian Criswell replied on Friday, September 01, 2006

In my code generator (which uses CodeSmith) I have set up recursive sub templates which walk down the object graph to load the child, grandchild, etc. objects.  There are corresponding stored procedure templates to generate the proper data structure as well.

JoOfMetL replied on Friday, September 01, 2006

Sorry, I don't understand. Do you have an example ?

Brian Criswell replied on Friday, September 01, 2006

No example that I am willing to release at this time, but I can elaborate a bit more...

You start with a fetch stored procedure template.  This template is passed the metadata for the root object that you are retrieving.  After generating the sql to retrieve that object, it then calls a subtemplate once for each child object or child collection of the root object.  The subtemplate generates the sql for the child object or collection and then calls itself for any grandchildren or the current child object.  Ultimately this structure:

Root
-ChildCollectionA
--ChildOfChildA
-ChildB
--GrandChildCollectionOfChildB

creates a series of sql select statements in the following order:

Root
ChildCollectionA
ChildOfChildA
ChildB
GrandChildCollectionOfChildB

There is a corresponding subtemplate for loading the resulting DataSet.

Did that help at all?

JoOfMetL replied on Saturday, September 02, 2006

Thank you for your explanation, now I understand.

Copyright (c) Marimer LLC