Hi All,
I found the answer. I was really desperate, that's why I posted here.
The following link
http://sdesmedt.wordpress.com/2006/09/04/nhibernate-part-4-mapping-techniques-for-aggregation-one-to-many-mapping/ provides the answer.
In short, in the user.hbm.xml I added this line
Code:
<many-to-one name="Role" class="Role" column="RoleID"/>
and in the Role.hbm.xml I added these lines
Code:
<bag name="Users" lazy="true">
<key column="RoleID"/>
<one-to-many class="User"/>
</bag>
In User.cs I added
Code:
public virtual Role Role { get; set; }
and in Role.cs I added
Code:
public virtual IList<User> Users { get; set; }
Now when I create a User object and set its Role, it is saved in the database with the appropriate RoleID.
Again sorry for posting and answering myself but it was really depressing to spend a lot of hours on such a simple thing.
Best regards,
Shehab.