Print Page | Close Window

Many to Many on same table

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=3411
Printed Date: 26-Apr-2024 at 12:07am


Topic: Many to Many on same table
Posted By: jradxl
Subject: Many to Many on same table
Date 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






Replies:
Posted By: DenisK
Date 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 - uploads/912/Console_T11812.zip



Print Page | Close Window