469,586 Members | 2,187 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,586 developers. It's quick & easy.

NHibernate Complex Table Mapping

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

Apr 18 '06 #1
1 2384

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

"Ram" <St****@gmail.com> wrote in message
news:11**********************@i39g2000cwa.googlegr oups.com...
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

Apr 18 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Fabiano | last post: by
reply views Thread by sternr | last post: by
1 post views Thread by sternr | last post: by
5 posts views Thread by Prem Kumar | last post: by
5 posts views Thread by igotyourdotnet | last post: by
4 posts views Thread by IceMan | last post: by
reply views Thread by Jacques Vandensavel | last post: by
14 posts views Thread by thj | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.