I have tables like this:
tblUsers
int UserID
string UserName
tblUsersInRoles
int UserID
int RoleID
tbleRoles
int RoleID
string RoleName
A user can be in many roles.
Is there a way to create my mapping file for my users so that my users object contains a list of Roles? I’ve figured out to do it so that I have a list of RoleID’s like this:
<bag name="Roles" table="tblUsersInRoles" cascade="all">
<key column="UserId"/>
<one-to-many class="UsersInRoles"/>
</bag>
Is there a way to take that the next step via the mapping file and store the roles themselves instead of just their ID’s?
Thanks for any help
You dont need UsersInRoles, to do it you can use this mapping:
And you can read this post about many to many. And about cascading – if you set cascade to all then deleting of user will couse deleting of his roles – I don’t think you need it.