zengcheng / codesmith

Automatically exported from code.google.com/p/codesmith
0 stars 0 forks source link

CSLA - Child_Update method on parent object throws exception when child object is root object #417

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a database with at least 2 tables.
2. Make a foreign key relationship between 2 of them.
3. Generate Switchable objects.
4. Create a root "child" object & a child "parent" object 7 try to update them.

What is the expected output? What do you see instead?
Exception thrown in the Child_Update method of the "parent" object in the 
foreign key relationship.

What version of the product are you using?
CodeSmith 5.2.1
CSLA templates r1707

Please provide any additional information below.
When the root object executes FieldManager.UpdateChildren(this, connection), it 
passes itself as a parameter, but there is no overload on the child object with 
this method signature. The CSLA framework still calls a Child_Update method, 
but the parameter passed is of the wrong type.
A workaround is to add a Child_Update method to the "child" object (which is 
the "parent" in the foreign key relationship) with the correct method signature.
In the attached project:
"Person" is the "parent" in the foreign key relationship & the "child" in the 
object tree
"PersonMoreInf" is the "child" in the foreign key relationship but the "root" 
in the object tree.
See the "Person.cs" file for an example of the workaround.

Original issue reported on code.google.com by rlbrac...@gmail.com on 18 Jun 2010 at 2:42

Attachments:

GoogleCodeExporter commented 9 years ago

Original comment by bniemyjski on 19 Jun 2010 at 8:37

GoogleCodeExporter commented 9 years ago
Hello,

I was unable to reproduce this in the latest version of the templates. If you 
can reproduce with the latest build, please provide a unit test or console 
sample application. This is what I used to test:

            Person person = Person.NewPerson();
            person.FirstName = "Blake";
            person.LastName = "Niemyjski";

            person = person.Save();

            PersonMoreInfo child = person.PersonMoreInfos.AddNew();
            child.Role = "Admin";

            person = person.Save();

            child.Role = "Administrator";

            person = person.Save();

Thanks
-Blake

Original comment by bniemyjski on 8 Jul 2010 at 6:11