NHibernate Complex Table Mapping

  • Thread starter Thread starter Ram
  • Start date Start date
R

Ram

Hey,

I'm having a trouble mapping a connecting between 2 of my tables.
We have 2 tables - the simplest "dept", "emp" tables which are mapped
to 2 classes.
Class Dept contains 2 properties for emps - 1 for manager and the
second for workers (Collection).
How can I map this?
We can add additional fields in the emp table that indicates the
property in the depts?

Thanks ahead


--Ram
 
Your NHibernate mapping for the department should look like this :

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" schema="dbo">
<class name="Dept, AssemblyName" table="Dept">
<bag name="Workers" inverse="true">
<key column="DepartmentID" />
<one-to-many class="Employee, AssemblyName" />
</bag>
<many-to-one name="Manager" column="ManagerID" class="Employee,
AssmblyName" />
</class>
</hibernate-mapping>

You should have a departmentId field in the emp table (i guess there should
be a one-to-one mapping between employees and departments) and a ManagerID
in the
department table too. AssemblyName should be the fully qualified name of
your assembly.
I hope this helps
 
Back
Top