Cloning bug in DataPortal?

Cloning bug in DataPortal?

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


GlennMiller posted on Monday, September 22, 2008

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?

lawrencek replied on Tuesday, September 23, 2008

yes I think your fix does make sence. 

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

GlennMiller replied on Tuesday, September 30, 2008

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);
}

Copyright (c) Marimer LLC