Many to Many Self Join

4 posts, 0 answers
  1. Chuck
    Chuck avatar
    30 posts
    Member since:
    Sep 2010

    Posted 15 Aug 2011 Link to this post

    Using 2011 Q2:

    I have a Use Case with a table that is joined to itself through a Many to Many Join Table.

    Example: Any User may or may not have security access to another User.  For ease of use there are two tables [Users] and [Users_Users].  [Users] has 1 field [Id].  [Users_Users] has 2 fields [AdminUserId] & [UserId].  Both [Users_Users].[AdminUserId] & [Users_Users].[UserId] are mapped to [Users].[Id]  A record in the [Users_Users] table means the [AdminUserId] has access to [UserId]; no record = no access.

    I have this modeled as a self join through the join table, but no changes are being committed to the [Users_Users] table.  After SaveChanges() the object reverts to the previous list.  The association has the "Is Managed" property set to True for both the "Source" and "Target".

    Any ideas?  I saw some documentation under the Fluent Mapping API, but I am just doing the database first approach.
  2. Zoran
    Admin
    Zoran avatar
    534 posts

    Posted 18 Aug 2011 Link to this post

    Hello Chuck,

     In this case, the issue could be related to the side from which you are inserting the records or making the relationship. For example if you have User1 that has rights on User2 and you are trying User1.ManagedUsers.Add(User2) and having the problem described, you can try the other way around: User2.ManagedBy.Add(User1). The idea is to change the direction you are adding to between the Source and the Target. However this is a workaround, we will have to have a deeper look into the issue as having the Managed setting set on both sides should synchronize the Source and Target collections thus, this problem should not be present.

    Please excuse us for any inconvenience this might cause you, if you have any further questions, please do not hesitate to get back to us.

    Regards,
    Zoran
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

  3. DevCraft banner
  4. Chuck
    Chuck avatar
    30 posts
    Member since:
    Sep 2010

    Posted 18 Aug 2011 Link to this post

    That was the problem.  I manually synchonized the objects in both directions and everything committed as expected.  I guess this relates back to the following thread:

    http://www.telerik.com/community/forums/orm/general-discussions/problem-with-insert-on-many-to-many.aspx

    So my only question is if this was fixed in the Q1 2011 release, is it broken again is Q2 2011?  I am having the same problem with standard many-to-many joins as well (not just self joins).  I should have thought of trying your suggestion myself -but I had previously worked around this by deleting the association and redrawing it in the opposite direction.  However, this was obviously not an option as I was drawing the association from itself to itself.
  5. Zoran
    Admin
    Zoran avatar
    534 posts

    Posted 24 Aug 2011 Link to this post

    Hi Chuck,

     I can not tell you accurately where did this functionality break especially for the self join case as it is specific one, but we will definitely have a look into the issue and do a final fix for it in our next major version. For the moment I believe that the workaround you are having is an acceptable one and I apologize for any inconvenience this might have caused you so far.

    All the best,
    Zoran
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's SQL Server Community Awards. We are competing in TWO categories and every vote counts! VOTE for Telerik NOW >>

Back to Top