Fluent NHibernate HasManyToMany() Mapping

后端 未结 1 1840
梦如初夏
梦如初夏 2020-12-10 06:06

I am having a problem in Fluent NHibernate example utilizing the Many-to-Many relationships. I tried to find out examples on a similar case, and I found tons, but I\'m still

相关标签:
1条回答
  • 2020-12-10 06:22

    Regarding to code I am using in my project I would define your manyTomany relations this way:

     public UsersMap()
        {
    ...
                HasManyToMany(x => x.Roles)
                    .WithTableName("UserInRoles")
                    .WithParentKeyColumn("Usernamepk")
                    .WithChildKeyColumn("RoleIdpk");
        }
    
      public RolesMap()
        {
    ...
                HasManyToMany(x => x.Users)
                    .WithTableName("UserInRoles")
                    .WithParentKeyColumn("RoleIdpk")
                    .WithChildKeyColumn("Usernamepk");
    
        }
    

    Such a definitions works for me. Check this first then decorate with LazyLoading and some other properties.

    0 讨论(0)
提交回复
热议问题