Search   

Sunday, February 05, 2012

Support » Support Forum

Register  Login

 Menu  
 
    

 Welcome!  
 


Welcome to the NDO support forum!

kreis.gif Please register/login at the site if you want to post a thread. We sometimes copy support mails of common interest to the forum. They appear with anonymous sender.
kreis.gif Please post your messages in English language if possible. You can do your posts also in German, we will translate your post and our answer so that all users of the forum can read your posts.
kreis.gif The forum software requires that javascript is enabled.
kreis.gif Please do not insert licence information or licence keys in forum posts.
kreis.gif If you know a good answer to a post of another user, feel free to reply!
kreis.gif The forum is monitored. We reserve the right to remove posts we consider not to be useful for other forum users.

   Print   

      
 NDO Support Forum  
 
SearchForum Home
  NDO-Forum postings in english please, if possible.  Developing with NDO  Object cloning...
 Object cloning
 
 7/23/2006 4:19:10 PM
Gerhard
12 posts


Object cloning
Hi Mirko, I would like to copy an existing database object (the copy is created by deep cloning), modify some properties and save (insert) the modified object to the database. If I make the new object persistent, I get the error that the object is already persistent. Is there any possibility to modify the copied object, that it is no longer recognized as persistent. I tried already to set the key as invalid (MyDbObject.NDOObjectId.Id.Invalidate()), but this doesn't solve the problem. The ID is automatically generated by server. Regards, Gerhard
 7/24/2006 11:08:51 AM
Mirko
109 posts
5th


Re: Object cloning
 Modified By Mirko  on 7/24/2006 11:09:57 AM)

Hi Gerhard,

how did you implement the deep cloning? If you can modify the cloning code, use the default object constructor and just spare out the NDO fields while copying the fields. All ndo field names start with _ndo. If you use the serialize/deserialize approach to clone the objects, you have to set the NDOObjectId = null and the NDOObjectState to NDOObjectState.Transient:

PersistenceManager pm = new PersistenceManager();
// Creating the object
Employee
emp = new Employee
();
emp.FirstName = "Mirko"
;
emp.LastName = "Matytschak"
;
pm.MakePersistent(emp);
pm.Save();
pm.UnloadCache();
// Cloning it
BinaryFormatter bf = new BinaryFormatter
();
MemoryStream ms = new MemoryStream
();
bf.Serialize(ms, emp);
ms.Seek(0, SeekOrigin
.Begin);
Employee emp2 = (Employee
)bf.Deserialize(ms);
// Setting the NDOObjectState and NDOObjectId

emp2.NDOObjectState = NDOObjectState
.Transient;
emp2.NDOObjectId = null
;
// Changing the data a little bit

emp2.FirstName = emp2.FirstName + "2"
;
pm.MakePersistent(emp2);
pm.Save();

Best Regards,
Mirko

 7/24/2006 3:29:10 PM
Gerhard
12 posts


Re: Object cloning
Hi Mirko, I'm using serialize/deserialize for deep cloning. Setting NDOObjectId = null and the NDOObjectState to NDOObjectState.Transient works. Many thanks. Regards, Gerhard
  NDO-Forum postings in english please, if possible.  Developing with NDO  Object cloning...
  SearchSearch  Forum HomeForum Home