I have following mapping definitions:
<class name="Role" table="Role" optimistic-lock="version" >
<id name="Id" type="Int32" unsaved-value="0" >
<generator class="native" />
</id>
<property name="RoleName" type="String(40)" not-null="true" />
<bag name="UsersInRole" generic="true" lazy="true" cascade="all" table="UserRoles" >
<key column="RoleId" />
<many-to-many column="UserId" class="SystemUser, Domain"/>
</bag>
and
<id name="Id" type="Int32" unsaved-value="0" >
<generator class="native" />
</id>
<property name="UserName" type="String(40)" not-null="true" unique="true" />
This mapping generates mapping table UserRoles, which has two columns - RoleId and UserId.
However, I'd like to add extra attributes to that relation - i.e. some enum values defining state of the relation as well as effective start & end dates.
Is it possible to do in nhibernate or do I need to add additional class here and change relation m-to-m into 2 relations [user] 1-to-m [user_role] m-to-1 [role] ?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…