Clone a set of objects

Posts   
 
    
timd
User
Posts: 5
Joined: 13-Mar-2008
# Posted on: 15-Apr-2008 22:43:26   

If I have a set of related objects (Parent/Child etc.) that I have retrieved from the DB and those objects generally use Identity values as their PK's, is there a way to clone the entire structure(Parents and their children etc.) into a new set of objects with new Identity values?

I need to make a complete copy of the objects and insert a NEW set of objects into the DB. Once the original set is marked as "Production" I cannot edit them anymore. So I want to copy the objects to a "new" set and edit the new set.

Thanks.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
timd
User
Posts: 5
Joined: 13-Mar-2008
# Posted on: 16-Apr-2008 13:55:57   

I have looked at several threads that all basically do the same thing. So I think I can "clone" these solutions, but I did not see anyone deal with Identity columns as PK values. Nearly all of my DB tables use Identity columns, so how do I reset the PK's when I deserialize the objects back to new entities?

timd
User
Posts: 5
Joined: 13-Mar-2008
# Posted on: 16-Apr-2008 14:48:15   

I had another idea. We are using the **Self-Service **model for our LLBLGen data access layer. If I have a parent/child where the children also have a parent/child to their children, etc for several layers deep.

Example: Tree1 Node1 NodeGroup1 TestGroup1 Test1 Node2 NodeGroup2 TestGroup2 Test2

So with a Self-Service model, if I retreive Tree1 from the DB and serialize it, does the serialization pickup the entire structure under Tree1, the entire object graph, or do I need to use Prefetch to ensure that all the objects are actually retrieved in memory before I serialize?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39903
Joined: 17-Aug-2003
# Posted on: 16-Apr-2008 16:31:28   

Serialization doesn't fetch data, so you have to prefetch everything you want to clone.

Frans Bouma | Lead developer LLBLGen Pro