Is Clone the same as Copy?Is Clone the same as Copy?
Old forum URL: forums.lhotka.net/forums/t/29.aspx
Cslah posted on Monday, May 08, 2006
I'm trying to make a copy of an object, as a new one, then display it to the user as a starting point. When I use Clone(), it seems like all I get is a reference?
Dim BO1 As MyBusObj
Dim BO2 As MyBusObj
BO1 = MyBusObj.GetMyBusObj(...)
BO2 = BO1.Clone()
At this point, for all practical purposes, it seems like BO2 is really just a reference to BO1. I can change a few things and save it, and everything is saved in BO1. Not sure what I'm missing here...
Thanks
xal replied on Monday, May 08, 2006
That doesn't sound right. Clone() uses serialization / deserialization to create a copy of an object, so there's no way you can have a direct reference to the original object. Are you inheriting from csla directly or are you using an intermediate class?. The behaviour you're describing sounds strange... Is there any more info you can throw in the mix? or is that the exact code you have? CSLA 1.x or 2.0? (although there shouldn't be any difference).
Andrés
dean replied on Monday, May 08, 2006
When you get the new object it is an exact copy of the old - so the key
fields will all be the same - so saving it will indeed update bo1. You
need to have a way to change these key fields. I have to copy an order
object - so I have a copy that will clone it and then create new key
fields - then you can save it - but you need tomake sure child keys are
updated too.
Dean
Copyright (c) Marimer LLC