Fluent Nhibernate many to many relationship using a surrogate primary key
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
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.
精彩评论