New Posts New Posts RSS Feed: Many to Many on same table
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Many to Many on same table

 Post Reply Post Reply
Author
jradxl View Drop Down
Newbie
Newbie


Joined: 14-Jun-2011
Posts: 30
Post Options Post Options   Quote jradxl Quote  Post ReplyReply Direct Link To This Post Topic: Many to Many on same table
    Posted: 26-Apr-2012 at 5:19pm
Hi,
(Code First, EF 4.2.0.0, DF 6.1.6)

Hopefully this code snippet is sufficient to explain.
The UserGroup Entity has these two properties
    public class UserGroup : BaseEntity     {
//....
  public RelatedEntityList<UserGroup> AllChildren { get { return null; } }         public RelatedEntityList<UserGroup> AllParents { get { return null; } }

The Entity's config is to related them Many to Many

    class UserGroupConfiguration : EntityTypeConfiguration<UserGroup>     {         internal UserGroupConfiguration()         {             this.HasMany(i => i.AllChildren)             .WithMany(c => c.AllParents)             .Map(mc =>             {                 mc.MapLeftKey("UserGroupId");                 mc.MapRightKey("ParentUserGroupId");                 mc.ToTable("UserGroupsHierarchy");             });         }     }

Such that it is Many to Many on itself.

Would you expect DF to automatically populate the "UserGroupsHierarchy" linker table
in the same way as a linker table between two different tables does.
It isn't at present!

Thanks
John





Edited by jradxl - 26-Apr-2012 at 5:25pm
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post Posted: 30-Apr-2012 at 4:18pm
Hi jradxl,

Yes it should and in my test, it does. I've attached my test solution here. Perhaps you can see what's different between mine and yours.

uploads/912/Console_T11812.zip
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down