2009-04-20 20 views
1

NHibernate的映射實體我有一個領域
MemID一個成員表 - 主鍵
BUSINESS_NAME
Business_Address
Business_Phone從字段在同一個表

我需要做哪些有來自性質的僱主類相同的會員表。
EmployerName
EmployerAddress
EmployerPhone

這裏是我的僱主映射

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

我以爲我可以映射這樣的會員類,但我得到一個「System.Collections.Generic.KeyNotFoundException:本鑑於鑰匙不在字典中。「

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

另請注意。由於當前系統的限制,我無法將業務信息移動到另一個表。 Business_Address和Business_Phone對另一個表是FK,這就是爲什麼它們是多對一映射。

回答

2

我不確定這是否是您要查找的內容,但您可以嘗試「組件」映射。這允許你在同一個表中有一個嵌套的類。

在谷歌搜索「nhibernate組件」 - 看起來hibernate.org網站仍然處於關閉狀態(!),但您可能能夠從頁面的Google緩存中獲取組件信息「第7章 - 組件信息映射「。

+0

這解決了我的問題非常感謝你! – Adam 2009-04-20 02:41:23

相關問題