EditableRootList and EditableChild

EditableRootList and EditableChild

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


smark posted on Thursday, October 12, 2006

Obviously, I am really getting into these templates Ricky provided, and to be clear, this is my first experience doing code generation.

I generated an editable root collection from the EditableRootList.cst template and then for a child of this collection, I generated an editable child using the EditableChild.cst template.

I am getting an error. In the root collection class, the DataPortal_Update method has a loop for child inserts:
-------------------------------------
foreach (AccessMode child in this)
                {
                    if (child.IsNew)
                        child.Insert ( cn );
                    else
                        child.Update ( cn );
                }
-----------------------------------

In the child of this root collection there is an internal insert method:
----------------------------------------------------------------
internal void Insert ( SqlConnection cn, AccessModes parent )
        {
            if (!IsDirty) return;

            ExecuteInsert ( cn, parent );
            MarkOld ();

            //update child object(s)
            UpdateChildren ( cn );
        }
--------------------------------------------------------------

As you can see, the Insert method in the child expects two parameters (cn and parent), whereas the insert in root collections' update method is only providing one (cn). For the time being, I have added the 'this' keyword as child.Insert (cn, this).

I am wondering if the templates need to be updated.

Thanks.

paulhumphris replied on Friday, October 13, 2006

I have experienced this problem also.  The problem appears to be in the EditableRootList.cst file, you will have to make the changes as follows.

Change

<%=Indent(i+1)%>child.Insert(<% if(objInfo.UseAdoTransaction) { %>tr<% } else {%>cn<%}%>);

 

to

 

<%=Indent(i+1)%>child.Insert(<% if(objInfo.UseAdoTransaction) { %>tr<% } else {%>cn<%}%>, this);

 

and also change

 

<%=Indent(i+1)%>child.Update(<% if(objInfo.UseAdoTransaction) { %>tr<% } else {%>cn<%}%>);

 

to

<%=Indent(i+1)%>child.Update(<% if(objInfo.UseAdoTransaction) { %>tr<% } else {%>cn<%}%>, this);

In effect you are simply adding the "this" value into the end of these two lines.

smark replied on Friday, October 13, 2006

Thanks Paul, I will make these changes. I have run into another related problem however; in the child's Insert method where the insert parameters are added to the SQL sproc, the child has the parent's Id (Guid) as a property:

cm.Parameters.AddWithValue ( "@PermissionCategoryID", _permissionCategoryID );

This is passing an empty Guid value, so I changed it to

cm.Parameters.AddWithValue ( "@PermissionCategoryID", parent.PermissionCategoryID );

Question is: am i missing something in the generated editable child class's xml property set? Do I need to make this change every time I generate an editable child?

Thanks.

rasupit replied on Friday, October 13, 2006

Smark,
In your scenario, you need to leave the parent property as blank in EditableChild.

See my posts at http://forums.lhotka.net/forums/thread/5082.aspx to understand when to use parent.

HTH,
Ricky

Copyright (c) Marimer LLC