Print Page | Close Window

detaching entity and then attaching it to another manager

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3111
Printed Date: 13-May-2026 at 6:38pm


Topic: detaching entity and then attaching it to another manager
Posted By: katit
Subject: detaching entity and then attaching it to another manager
Date 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?
 



Replies:
Posted By: DenisK
Date 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 - http://drc.ideablade.com/xwiki/bin/view/Documentation/entities-import  for more details.

Hope this helps.



Print Page | Close Window