AnantLabs / codesmith

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

CSLA - EditableRootList object throws exception on Save #412

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.  Generate an EditableRootList object.  In your Entities.csp, put the table 
in the EditableRootList category under entities, and EditableChild under 
entities.
2.  Generate the code and run your application.  Edit one of the list items and 
save the change
3.  You will receive a NotSupportedException: Cannot directly save a child 
object

What is the expected output? What do you see instead?

The save should be successful instead of producing an exception.

What version of the product are you using?

CodeSmith: v5.2.1, CSLA Templates: v2.0.1.1706, CSLA Framework: v4.0.0.

When looking at the templates, I believe that the code generation chose to 
generate the wrong code when generating DataPortal_Update() method of the 
EditableRootList object.  I'm not sure how the code generation is supposed to 
work for this situation, but the generation works correctly when I make the 
following changes:

DataPortalUpdateList.cst
Line 19
Change <% if(IsChildBusinessObject(string.Empty)) { %>
To <% if(IsChildBusinessObject("List")) { %>

EntityCodeTemplate.cs
Line 375 and Line 401
Add the following case statement to the switch statement:
case Constants.EditableRootList:

Making these changes allows the if statement at Line 19 in 
DataPortalUpdateList.cst to evaluate to true.  When I setup my generation, I 
put my table in both the EditableRootList Category (under 6b) and EditableChild 
Category(under 6a).  It seems like my child object isn't getting correctly 
detected as a child.

As I said, I'm not really familiar with this portion of the templates, and my 
fix probably isn't the correct one, but maybe this info can help somebody more 
knowledgable find the root cause.

Original issue reported on code.google.com by RoyMunso...@gmail.com on 17 Jun 2010 at 4:32

GoogleCodeExporter commented 9 years ago

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

GoogleCodeExporter commented 9 years ago

Original comment by bniemyjski on 1 Jul 2010 at 7:24

GoogleCodeExporter commented 9 years ago
Hello,

I set this up using the Category Table in PetShop. Here is the code I tested it 
against:

            CategoryList list = CategoryList.GetByName("Birds");
            Category subCat = list.AddNew();
            subCat.CategoryId = "birds-2";
            subCat.Name = "Birds";
            subCat.Description = "Birds";

            list = list.Save();

I was unable to reproduce. Could you please supply a sample solution or csp \ 
unit test that works against PetShop.

Thanks
-Blake Niemyjski

Original comment by bniemyjski on 1 Jul 2010 at 8:27

GoogleCodeExporter commented 9 years ago
Hi Blake,

I just re-ran my problem scenario with build 1758, and I am also unable to 
reproduce the issue.  The correct code is now being generated.  Something must 
have fixed it between 1706 and 1758.  Sorry I forgot to re-test it after 
updating.  Thanks for looking into it!

Original comment by RoyMunso...@gmail.com on 1 Jul 2010 at 9:33

GoogleCodeExporter commented 9 years ago
Hello,

Thanks for keeping me updated!

Thanks
-Blake Niemyjski

Original comment by bniemyjski on 8 Jul 2010 at 9:55