Print Page | Close Window

Create New Entity when using Multiple EntityManagers

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=2138
Printed Date: 07-Apr-2025 at 3:02am


Topic: Create New Entity when using Multiple EntityManagers
Posted By: cjohnson84
Subject: Create New Entity when using Multiple EntityManagers
Date Posted: 09-Sep-2010 at 10:19am

We are investigating the use of multiple entity managers in our Silverlight application.

My question is if I want to create a new entity, how do I specify which entity manager to add it to when I call "AddToManager()"?
 
The EntityAspect.EntityManager property is readonly.



Replies:
Posted By: sbelini
Date Posted: 09-Sep-2010 at 3:53pm
Hi,
 
try using .AddEntity instead:
 
myEntityManager.AddEntity(myEntity);
 
The API documentation states:
The associated EntityManager will either be the EntityManager that was called to create this Entity (M:IdeaBlade.EntityModel.EntityManager.CreateEntity``1) or that was used to generate its ids ( ms-its:C:%5CProgram%20Files%20%28x86%29%5CDevForce%202010%5CDocumentation%5CIdeaBladeDevForce2010HelpReference.chm::/topic2880.html - IdeaBlade.EntityModel.EntityManager.GenerateId ) If neither of these cases apply, then the ms-its:C:%5CProgram%20Files%20%28x86%29%5CDevForce%202010%5CDocumentation%5CIdeaBladeDevForce2010HelpReference.chm::/topic2829.html - EntityManager 's DefaultManager"/> will be used. There is no difference between AddToManager and M:IdeaBlade.EntityModel.EntityManager.AddEntity(IdeaBlade.EntityModel.Entity). Use either method to add a business object created by the ms-its:C:%5CProgram%20Files%20%28x86%29%5CDevForce%202010%5CDocumentation%5CIdeaBladeDevForce2010HelpReference.chm::/topic2857.html - IdeaBlade.EntityModel.EntityManager.CreateEntity method to the EntityManager cache. The object must have a "detached" ms-its:C:%5CProgram%20Files%20%28x86%29%5CDevForce%202010%5CDocumentation%5CIdeaBladeDevForce2010HelpReference.chm::/topic2607.html - IdeaBlade.EntityModel.EntityAspect.EntityState , must not have ever been associated with another EntityManager and must have a unique EntityKey within the EntityManager to which it will be added.
 
I hope it helps,
   Silvio.


Posted By: cjohnson84
Date Posted: 10-Sep-2010 at 4:28am
Thank you Silvio.  Your suggestion worked.  I was looking at this problem from the wrong point of view.



Print Page | Close Window