Print Page | Close Window

Copying/Cloning models between SQL Instances

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce Classic
Forum Discription: For .NET 2.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=600
Printed Date: 19-Sep-2025 at 11:49pm


Topic: Copying/Cloning models between SQL Instances
Posted By: PJones
Subject: Copying/Cloning models between SQL Instances
Date Posted: 11-Dec-2007 at 10:30am
I have a need to read an object model from one SQL (remote) database and persist that model to another SQL (local) database.  I also need to be able to push the local DB info back to the remote.
 
Are there any built-in features and/or best practices for accomplishing this?
 
 



Replies:
Posted By: davidklitzke
Date Posted: 12-Dec-2007 at 8:34am
Here is some sample code for cloning.  It handles such problems as:
 
o A cloned object cannot have a primary key identical to the object from which it is being cloned.
o Handling of foreign keys
 
http://www.ideablade.com/forum/uploads/20071212_113325_EntityCloner.zip - uploads/20071212_113325_EntityCloner.zip


Posted By: PJones
Date Posted: 13-Dec-2007 at 9:35am
I have this same code sample (from tech support) already.
 
When you say "handles" foreign keys what do you mean?
 
What I want is the object and its entire dependent tree including all data in all child objects cloned.  This code only clones the target object and skips all relations downward and makes an exact copy of foreign key values which will not always work (ie. if I clone a patternCollection child of a Project class I don't want it to be the child of Project 1 (cloned) but the child of the newly created (cloned) Project object).
 
Pete


Posted By: orcities
Date Posted: 14-Mar-2008 at 11:15am
Has this been resolved. I am wanting the same thing. A clone of the object and all of it's references.



Print Page | Close Window