New Posts New Posts RSS Feed: detaching entity and then attaching it to another manager
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

detaching entity and then attaching it to another manager

 Post Reply Post Reply
Author
katit View Drop Down
Senior Member
Senior Member


Joined: 09-Sep-2011
Posts: 146
Post Options Post Options   Quote katit Quote  Post ReplyReply Direct Link To This Post Topic: detaching entity and then attaching it to another manager
    Posted: 24-Nov-2011 at 3:04pm
I'm trying to do following:
 
1. Create entity and attach it to EntityManager. I do attach it to manager ONLY for the reason that I need verification to work. VerificationManager can't be assigned to detached entity.
 
this.MailItem = new SYSMailItem
                {
                    MailItemGKey = Guid.NewGuid(),
                    SenderKey = (this.SecurityService.User as UserPrincipal).UserKey
                };
this.EntityManager.AddEntity(this.MailItem); 
 
2. When I'm done with editing entity - I need to pass it into my "manager" to save it.
 
this.EntityManager.RemoveEntity(this.MailItem, true);
this.MailService.SendMail(this.MailItem...
 
3. Inside MailService I'm trying to attach this entity back to another manager for saving:
 
this.entityManager.AddEntity(mailItem);
I'm getting following error:
This entity already belongs to or was previously associated with another EntityManager and has a temporary key defined by that EntityManager
 
Yes, sure. I agree with this message :)
But how do I detach so it can be attached to different manager?
 
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post Posted: 29-Nov-2011 at 4:56pm
Hi katit;

My suggestion in this use case is to use EntityManager.ImportEntities. See http://drc.ideablade.com/xwiki/bin/view/Documentation/entities-import for more details.

Hope this helps.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down