Hi,
I would like to deep copy an Entity and I am looking for the best way to do it. I am also concerned about performances.
I plan to have all my entities implementing ICloneable where Clone() will basically shadow copy and Clone all references.
For instance:
[DataContract()]
class MyEntity {
public int id;
public string name;
public EntitySet<AnotherEntity> myOtherEntity;
}
MyEntity Clone() {
Entity ent = new Entity();
ent.name = this.name;
ent.myOtherEntity = this.myOtherEntity.Clone();
return ent;
}
Is it a good way of doing it? Or should I load the entity with linq, remove all primary keys (set id to 0) and then use a Create(entity) function to duplicate it? Could reflection be a valid solution too (not too slow)? At least reflection can avoid the issue when updating my entity class (new members for instance) without updating the Clone function...
Thanks, Xavier