New Posts New Posts RSS Feed: Cloning an Entity
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Cloning an Entity

 Post Reply Post Reply
Author
pkarsh View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 14-Jun-2007
Location: United States
Posts: 32
Post Options Post Options   Quote pkarsh Quote  Post ReplyReply Direct Link To This Post Topic: Cloning an Entity
    Posted: 20-Mar-2008 at 11:27am
The short answer is that in order for the Entity you have created by cloning (aClone in your example) to recognize relational entity objects referenced by dot syntax (e. g. aClone.Address), you have to call AddToManager() on the newly-generated entity. In your example, before you do the AddToManager you will have to do something to make the primary key of aClone unique. As it stands, aClone will have the same primary key value as the entity it was cloned from and the AddToManager call will fail.
Back to Top
orcities View Drop Down
Senior Member
Senior Member
Avatar

Joined: 28-Aug-2007
Location: United States
Posts: 454
Post Options Post Options   Quote orcities Quote  Post ReplyReply Direct Link To This Post Posted: 19-Mar-2008 at 10:22am

I am using the Cabana framework.

/// <summary>Create clone of this entity; it is associated with but NOT attached to a PM</summary>

/// <remarks>

/// The clone gets its <see cref="PersistenceManager"/> from this entity.

/// See <see cref="Clone(PersistenceManager)"/>.

/// </remarks>

public virtual Entity Clone() {

return Clone(PersistenceManager);

}

 

public virtual Entity Clone(PersistenceManager pManager) {

Entity aClone = pManager.CreateEntity(GetType());

      aClone.ItemArray = ItemArray;

      return aClone;

}

 
I would think that overriding the associated object would be suffice. But the reference doesn't take.
Back to Top
pkarsh View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 14-Jun-2007
Location: United States
Posts: 32
Post Options Post Options   Quote pkarsh Quote  Post ReplyReply Direct Link To This Post Posted: 19-Mar-2008 at 10:14am
I meant the code for your Clone method. The Entity class does not have a Clone method so you must have added your own Clone method. Also, in your example, which Entity is the parent and which is the child?

Edited by pkarsh - 19-Mar-2008 at 10:16am
Back to Top
orcities View Drop Down
Senior Member
Senior Member
Avatar

Joined: 28-Aug-2007
Location: United States
Posts: 454
Post Options Post Options   Quote orcities Quote  Post ReplyReply Direct Link To This Post Posted: 19-Mar-2008 at 8:07am
Contact-Phone is 1-to-many but I have examples that are 1-to-1 that do the same thing.
Back to Top
orcities View Drop Down
Senior Member
Senior Member
Avatar

Joined: 28-Aug-2007
Location: United States
Posts: 454
Post Options Post Options   Quote orcities Quote  Post ReplyReply Direct Link To This Post Posted: 19-Mar-2008 at 8:05am
Originally posted by orcities

 
Example:
 
Contact aClone = aContact.Clone();
aClone.Address = SomeAddress;
 
I have also tried attaching a PM to the clone:
Contact aClone = aContact.Clone(MainPM);
 
 
Back to Top
pkarsh View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 14-Jun-2007
Location: United States
Posts: 32
Post Options Post Options   Quote pkarsh Quote  Post ReplyReply Direct Link To This Post Posted: 18-Mar-2008 at 3:33pm
Could you show us your cloning code? Also, how is the relation between Contact and Address defined (i. e. 1-to-1 or 1-to-many and who is the parent and who is the child?)


Edited by pkarsh - 18-Mar-2008 at 3:45pm
Back to Top
orcities View Drop Down
Senior Member
Senior Member
Avatar

Joined: 28-Aug-2007
Location: United States
Posts: 454
Post Options Post Options   Quote orcities Quote  Post ReplyReply Direct Link To This Post Posted: 18-Mar-2008 at 10:47am
When cloning an entity it only clones the base entity. When I try and attach to a referenced object it still does not attach. Why is this.
 
Example:
 
Contact aClone = aContact.Clone();
aClone.Address = SomeAddress;
 
Outcome:
aClone.Address still has values that are blank.
 
 


Edited by orcities - 18-Mar-2008 at 10:47am
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down