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 Answer 1

2

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."

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.