Print Page | Close Window

ImportEntities and n-n relations

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=3008
Printed Date: 13-May-2026 at 6:18pm


Topic: ImportEntities and n-n relations
Posted By: Walid
Subject: ImportEntities and n-n relations
Date Posted: 13-Oct-2011 at 2:44am
I'm trying to implement a sandbox editor for an entity having an n-n relation and have some troubles when I import the modified (and committed) entity back to the original manager.
For example, lets say we have Users (Administrator, User1, User2) and Roles (Admins, Readers,...).
A User has n-roles (User.Roles) ex User1.Roles = {Admins, Readers}, the entity relation is called UsersInRoles
After editing the existing user and removing some roles (importing it in a new EM then User1.Roles.Remove(Admins)) , re-importing it back (with a correct EntityGraph collection and OverrideChanges merge strategy) to the original EntityManager, leaves the User1.Roles collection untouched, the removed role Admins still remains in the Roles collection. If I refresh the original EM reloaded User has the correct roles.
Is it a limitation of DevForce or a bug ?
Sample Code :
...
public User ImportUser(User user, EntityManager manager)
{
...
var spans = new List<EntitySpan>() {new EntitySpan(typeof(User), EntityRelations.UsersInRoles)};
manager.ImportEntities(user.EntityAspect.EntityManager.FindEntityGraph(new object[] {user}, spans, EntityState.AllButDetached));
return = (User)manager.FindEntity(user.EntityAspect.EntityKey);
}
...
var sandboxEM = new MyEntityManager();
var sandboxUser = ImportUser(editingUser, sandboxEM);
...
sandboxUser.Roles.Remove(AdminRole);
...
sandboxEM.SaveChangesAsync(...);
...
ImportUser(sandboxUser, originalEM);
...
editingUser.Roles contains AdminRole !!!!
Thanks,



Replies:
Posted By: DenisK
Date Posted: 19-Oct-2011 at 6:54pm
Hi Walid;

I was able to reproduce your issue but let me clarify this first with a senior engineer and get back to you.


Posted By: Walid
Date Posted: 19-Oct-2011 at 11:48pm
Ok, thank you Denis.

-------------


Posted By: Walid
Date Posted: 27-Oct-2011 at 1:15am
Any news Denis ?

-------------


Posted By: DenisK
Date Posted: 31-Oct-2011 at 11:46am
Hi Walid;

Sorry for the delayed reply. Yes, this is a bug and I have a filed a bug report for it. It should (but no guarantee) be fixed in the next release.


Posted By: smi-mark
Date Posted: 31-Oct-2011 at 11:52am
This was one of the issues I was having a few months back.

http://www.ideablade.com/forum/forum_posts.asp?TID=2596&KW=smi%2Dmark&title=possible-bug-import-entities

Glad it's getting fixed. Can you update us when you know if it's going to be in the next version?


Posted By: DenisK
Date Posted: 01-Nov-2011 at 4:35pm
Will do.

I'm not sure if they're actually the same issue though. I have to look into it again since it's been a while.


Posted By: smi-mark
Date Posted: 01-Nov-2011 at 4:51pm
I've actually just found a solution for the main issue. Now I'm just left with the same issue that Walid has. I'll post what I've had to do in my other thread.



Print Page | Close Window