代码之家  ›  专栏  ›  技术社区  ›  Kevin Pang

流畅的无纤维问题

  •  8
  • Kevin Pang  · 技术社区  · 17 年前

    用户-用户ID(int)

    我想要的是我的域中的“User”类具有角色的IList。如何构建Fluent NHibernate映射来实现这一点?

    4 回复  |  直到 17 年前
        1
  •  13
  •   SecretDeveloper    17 年前

    您要查找的是一组元素的集合,在标准hbm映射中是:

    <set name="Roles" table="UserRoles">
      <key column="UserID" />
      <element column="Role" />
    </set>
    

    HasMany<string>(x => x.Roles)
      .AsElement("Role");
    

    您可能还需要使用指定密钥名称 WithKeyColumn(string)

        2
  •  4
  •   Chris Marisic    16 年前

    FWIW这在今天已经发生了微小的变化。当前映射为

    HasMany<string>(x => x.Roles)
      .Element("Role");
    
        3
  •  0
  •   lomaxx    17 年前

    我相信会的

    public User()
      {
        Id(x => x.UserID);
        HasMany<UserRoles>(x => x.UserRoles).AsBag();
      }
    

    您还必须确保映射UserRoles类

        4
  •  0
  •   Assaf Lavie    17 年前

    这也起到了作用:

    HasMany<Role>(u => u.Roles)
                    .WithTableName("UserRoles")
                    .Component(role => role.Map(r => r.Name))
                    .AsList();
    

    您不需要映射角色或用户角色。

    IEquatable < Role > ;.