开发者

Fluent Nhibernate many to many relationship using a surrogate primary key

开发者 https://www.devze.com 2023-02-05 18:30 出处:网络
I have many to many relationship in my application and I am using fluent nhibernate. A login can have many roles.( A role can also have many logins ).

I have many to many relationship in my application and I am using fluent nhibernate.

A login can have many roles. ( A role can also have many logins ).

I have see开发者_JAVA百科n many examples of using a composite primary key.

        HasManyToMany<Role>(x => x.Roles).Table("Role")
            .ParentKeyColumn("RoleId")
            .ChildKeyColumn("LoginId");

Do you know if Fluent/NHibernate supports Many to Many relationships without having the database associative entity (Login_Role) requiring a composite primary key.

I would prefer to have Login_Role use a surrogate primary key.

Cheers, Andrew

Fluent Nhibernate many to many relationship using a surrogate primary key


You can use an idbag:

<idbag name="Roles" table="Login_Role">
  <collection-id type="int" column="id">
    <generator class="hilo"/>
  </collection-id>
  <key column="LoginId"/>
  <many-to-many class="Role" column="RoleId"/>
</idbag>

I don't think Fluent exposes it yet.

0

精彩评论

暂无评论...
验证码 换一张
取 消