CSLA .NET

From Rockford Lhotka's Expert C# 2005 and VB 2005 Business Objects books

Welcome to CSLA .NET Sign in | Join | Help
in Search

Cloning bug in DataPortal?

Last post 09-30-2008, 11:20 AM by GlennMiller. 2 replies.
Sort Posts: Previous Next
  •  09-22-2008, 8:55 AM 26468

    Cloning bug in DataPortal?

    In CslaCE.DataPortal.Update about halfway down, there's a try block that calls Clone before calling proxy.Update. The call to Clone crashes in our code because the business object obj doesn't implement IClonable. It looks like the non-mobile code implements IClonable on BusinessBase, but the mobile code doesn't.

    We could fix it by remembering to manually implement IClonable on all our business objects. Instead we chose to do what Rocky does in 3.5, which is to modify DataPortal.Update to add a check whether obj implements IClonable, and only call Clone() if it does.

    Does our "fix" to DataPortal.Update make sense, or is the intent for the developer to implement IClonable on every business object?
  •  09-23-2008, 5:57 PM 26509 in reply to 26468

    Re: Cloning bug in DataPortal?

    yes I think your fix does make sence. 

    if you can please post the fix I'll update the svn code.

  •  09-30-2008, 11:20 AM 26752 in reply to 26509

    Re: Cloning bug in DataPortal?

    Originally the try block mentioned looked like this:

    try
    {
    // when using local data portal, automatically
    // clone original object before saving
    obj = ((ICloneable)obj).Clone();
    result = proxy.Update(obj, dpContext);
    }

    We changed it to this:

    try
    {
    // when using local data portal, automatically
    // clone original object before saving
    ICloneable cloneable = obj as ICloneable;
    if(cloneable != null)
    obj = cloneable.Clone();
    result = proxy.Update(obj, dpContext);
    }

View as RSS news feed in XML

Please contact Magenic for your .NET consulting and CSLA .NET mentoring needs.
Please consider making a donation to help support the ongoing development of CSLA .NET.

Make donation through PayPal - it's fast, free and secure!
Why donate?
Powered by Community Server, by Telligent Systems