AnantLabs / codesmith

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

Problem with AddNewCore when generating and EditableRootList in a CSLA Silverlight App. #376

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.  Generate an EditableRootList object
2.
3.

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

In the MyObjectList.Generated.cs file, it creates the following code:

protected override MyObject AddNewCore()
        {
            MyObject item = Business.MyObject.NewMyObject();

            bool cancel = false;
            OnAddNewCore(ref item, ref cancel);
            if (!cancel)
            {
                // Check to see if someone set the item to null in the 
OnAddNewCore.
                if(item == null)
                    item = Business.MyObject.NewMyObject();

            }

            Add(item);
            return item;
        }

This doesn't work as Silverlight is expecting this method to look like 
this:

protected override void AddNewCore()
        {
            var child = MyObject.NewMyObject();
            Add(child);
        }

Also, the OnAddNewCore partial methods don't seem to work on the SL side, 
as they are defined in the MyObject.DataAccess.cs file, which can't be 
included on the Silverlight Side.  The above AddNewCore method won't work 
straight up with the templates either, as there are only 
MyObject.NewMyObjectAsync(handler) methods available to you.  That's fine 
if you actually need to make a call back to your server to set your new 
object up, but in many cases you don't need to incur this performance 
penalty, and you can simply create your object client side.  In order to 
facilitate this, I needed to add something like the following to 
MyObject.cs

#if SILVERLIGHT

        internal static MyObject NewMyObject()
        {
            return DataPortal.CreateChild<MyObject>();
        }

#endif

What version of the product are you using?

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

Please provide any additional information below.

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

GoogleCodeExporter commented 9 years ago

Original comment by bniemyjski on 10 Jun 2010 at 2:50

GoogleCodeExporter commented 9 years ago
Hello,

This has been fixed in revision 1704. I have fixed all of the issues minus your 
last change. 

internal static MyObject NewMyObject()
        {
            return DataPortal.CreateChild<MyObject>();
        }

Could you please create a patch for this and attach it to a new google code 
issue.

Thanks
-Blake Niemyjski

Original comment by bniemyjski on 15 Jun 2010 at 2:42

GoogleCodeExporter commented 9 years ago

Original comment by bniemyjski on 21 Jun 2010 at 8:08