New Posts New Posts RSS Feed: Getting Error while adding entity
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Getting Error while adding entity

 Post Reply Post Reply
Author
keval View Drop Down
Newbie
Newbie
Avatar

Joined: 16-Apr-2008
Location: India
Posts: 15
Post Options Post Options   Quote keval Quote  Post ReplyReply Direct Link To This Post Topic: Getting Error while adding entity
    Posted: 17-Jul-2008 at 12:12am
Hi,
 
I m getting the following error while adding entity to entitymanager
 
"This Entity already belongs to another EntityManager"
 
Following is the code snippet where i get the error

DataSet.AddEntity(mmp);

- DataSet is EntityManager
- mmp is Entity
 
Can u please guide me what can be the error. AS i m not adding this entity to anywhere in the application thenalso getting the error.
 
Thanks in advance.
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 17-Jul-2008 at 10:34am
Well, you'll get this error if the entity you're trying to add already has its .EntityManager property set and the entity is in a non-detached state.  How did the entity come into existence?  Did you query for it, restore it from an entity set, or create it?   If you do want to add the entity to this EntityManager, first call entity.RemoveFromManager to detach it from its current EntityManager.  Once added, the entity's state will be Added, and when SaveChanges is called it will be inserted to the database.  If you don't want this behavior, then look at using mgr.ImportEntities to "move" entities between Entity Managers.
Back to Top
keval View Drop Down
Newbie
Newbie
Avatar

Joined: 16-Apr-2008
Location: India
Posts: 15
Post Options Post Options   Quote keval Quote  Post ReplyReply Direct Link To This Post Posted: 18-Jul-2008 at 12:10am
Hi Kim,
 
Thanks for the reply.
 
I have resolved the issue this morning. But its a very descriptive as well as useful reply from ur side.
That will be very useful for us to optimize the code as well as improve performance. I will try this thing in my code and check it.
 
Thanks again. 
 
Back to Top
keval View Drop Down
Newbie
Newbie
Avatar

Joined: 16-Apr-2008
Location: India
Posts: 15
Post Options Post Options   Quote keval Quote  Post ReplyReply Direct Link To This Post Posted: 18-Jul-2008 at 12:11am
Hi Kim,
 
Thanks for the reply.
 
I have resolved the issue this morning. But its a very descriptive as well as useful reply from ur side.
That will be very useful for us to optimize the code as well as improve performance. I will try this thing in my code and check it eventhough i have solved it.
 
Thanks again. 
 
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down