The EntitySpaces Community

Share and learn about the EntitySpaces Architecture.
Welcome to The EntitySpaces Community Sign in | Join | Help
in
Home Forums Photos

Problems with heirarchies not updating (Beta 4)

Last post 06-07-2008, 7:02 PM by tetious. 2 replies.
Sort Posts: Previous Next
  •  06-07-2008, 5:00 PM 9691

    Problems with heirarchies not updating (Beta 4)

    I'm having difficulty with the many to many hierarchy not updating correctly after a save. I have a simple unit test that reproduces the problem.

    The relationship is AppUser -> AppUserRoleAssn -> Role, with the primary key of Role and AppUser migrated to the assn. I'm freshly creating the user in a setup fixture, and deleting in a teardown, so it should be clean. I also verified it is getting added to the database, and if I set UpToRoleCollection = null and save the user, the test passes, as that seems to force a refresh.

    Please let me know if you have any ideas as to what I'm doing wrong. Or maybe I found a bug. :)

        Code:
                Assert.That(u.UpToRoleCollection.Count, Is.EqualTo(0));
    Role r = new Role();
    r.LoadByName("admin");
    Assert.That(r.RoleName,Is.EqualTo("admin"));
    u.AssociateRoleCollection(r);
    u.Save();

    Assert.That(u.UpToRoleCollection.Count, Is.EqualTo(1)); // Count is still ZERO here, assert fails
  •  06-07-2008, 6:51 PM 9693 in reply to 9691

    Re: Problems with heirarchies not updating (Beta 4)

    Our hierarchical sub-objects are lazy-loaded from the database and cached. The Associate/Dissociate methods do not check to see if there is already an in-memory cached object, they just add a new row to the Associative table, ready to be saved with the parent entity.

    If you remove the first assert (thereby, not creating the empty cache), or, as you say, set UpToRoleCollection = null at any time before the last assert (which will flush the cache and force a re-load), the test should pass.

    I think some users, who wish to avoid hitting the database again, are maintaining the in-memory cache themselves by combining an Associate/Dissociate with an AttachEntity/DetachEntity.


    David Neal Parsons
    www.entityspaces.net
  •  06-07-2008, 7:02 PM 9694 in reply to 9693

    Re: Problems with heirarchies not updating (Beta 4)

    I see. That makes sense. Both of your suggestions also worked just fine. I like the Attach/Detach idea. I didn't think of that.

    Thanks!

View as RSS news feed in XML