Hi,
i Have a table Called UserRoles. In this Table i am Having compositeprimarykey(UserId,RoleCode).
UserId,Rolecode is also Foreign Keys Which Refers to OtherTables called Users and Roles Respectively.
Code:
class Userroles :EntityBase
{
private User user;
private Roles role;
//private bool _isActive;
private string _createdBy;
private DateTime _createdDateTime;
private string _updatedBy;
private DateTime _updatedDateTime;
[DataMember]
public virtual User User
{
get
{
//if (addresstype == null)
//{
// addresstype = new AddressType();
//}
return user;
}
set
{
if (user == value) return;
user = value;
Notify("User");
}
}
[DataMember]
public virtual Roles Roles
{
get
{
//if (addresstype == null)
//{
// addresstype = new AddressType();
//}
return role;
}
set
{
if (role == value) return;
role = value;
Notify("Roles");
}
}
}
public class User : EntityBase
{ // Some Properties Here}
public class Roles : EntityBase
{ //Some Properties Here}
Code:
UserRoles.hbm.xml
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="Core.Modules.Security.DomainModel.Userroles, Core" table="SYSUSERROLES" lazy="false">
<composite-id>
<key-property name="_user" column="USERCODE"/>
<key-property name="_role" column="ROLECODE"/>
</composite-id>
<many-to-one name="User" class="Core.Modules.Security.DomainModel.User, Core" column="USERCODE"/>
<many-to-one name="Roles" class="Core.Modules.Security.DomainModel.Roles, Core" column="ROLECODE"/>
</class>
</hibernate-mapping>
Is this mapping Correct?