Deep Copy

Posts   
 
    
Chad2
User
Posts: 8
Joined: 19-Mar-2007
# Posted on: 19-Mar-2007 13:13:05   

Haven't been on the forum lately since everything has been working so well smile ..

So, just to confirm.. Is the best way to do a deep copy of an entity still?

        IEntity2 lTargetEntity;
        MemoryStream lStream = new MemoryStream();
        BinaryFormatter lFormatter = new BinaryFormatter();
        lFormatter.Serialize(lStream, sourceEntity);
        lStream.Seek(0, SeekOrigin.Begin);
        lTargetEntity = (IEntity2) lFormatter.Deserialize(lStream);
        MarkEntityAsNew(lTargetEntity);

Thanks,

Aurelien avatar
Aurelien
Support Team
Posts: 162
Joined: 28-Jun-2006
# Posted on: 19-Mar-2007 15:27:05   

Hi,

After a search on the forum, i didn't find a easier way to do that.

Cheers,

Aurélien

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 20-Mar-2007 12:02:36   

Correct, a serialization is the 'best' option as you get full copies of all objects involved.

Frans Bouma | Lead developer LLBLGen Pro
Chad2
User
Posts: 8
Joined: 19-Mar-2007
# Posted on: 20-Mar-2007 13:21:28   

Btw Otis, why haven't you implemented your own DeepCopy into the framework? I've been thinking about this for a while so I expect you have a real interesting reason... do you? smile

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 20-Mar-2007 13:35:34   

As it would come down to a serialization of the graph and deserialization of the data into a new graph, as the overhead other wise would be too much (every object has to be copied)

So what I then could do is offer a utility method somewhere which does this, but I left that to the developer (you simple_smile ) to implement that, so you perhaps could use your own serialization logic if you had that in place which perhaps was faster.

Frans Bouma | Lead developer LLBLGen Pro