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,