tags:

views:

854

answers:

1

I have a Member Table with fields
MemID - Primary Key
Business_Name
Business_Address
Business_Phone

I need to make an Employer Class which has properties that come from the same Members Table.
EmployerName
EmployerAddress
EmployerPhone

Here is my Employer Mapping

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="true">
<class name="Employer, Entities" lazy="true" table="Members" dynamic-update="true">
     <id name="MemberID" column="MemID" type="Int64">
      <generator class="native" />
     </id>
     <many-to-one name="EmployerAddress" column="Business_Address" class="Address, Entities" lazy="proxy" />
     <many-to-one name="EmployerPhone" column="Business_Phone" class="Phone, Entities" lazy="proxy"/>
     <property name="EmployerName" column="Business_Name" not-null="false" />
    </class>
</hibernate-mapping>

I thought that I could map the Members class like this but I get a "System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary."

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="true">
<class name="Member, Entities" lazy="true" table="Members" dynamic-update="true">
<id name="MemberID" column="MemID" type="Int64">
<generator class="native" />
</id>
<one-to-one name="EmployerInformation" class="Employer, Entities"  lazy="false"/>
    </class>
</hibernate-mapping>

Also please note. I can't move the Business Information to another table due to constraints on the current system. Business_Address and Business_Phone are FK to another table that is why they are many-to-one mappings.

+1  A: 

I'm not sure if this is what you're looking for, but you could try the "component" mapping. This allows you to have a nested class within the same table.

Search google for "nhibernate component" - it appears that the hibernate.org site is still down (!), but you might be able to get the component info from the google cache for the page "Chapter 7 - Component Mapping."

Andy White
That solved my problem thank you very much!
Adam
Awesome, I'm glad that helped!
Andy White