2010-07-15 59 views
1

目前我使用提取條件數據多到一個在HBM文件元素像下面....NHibernate的 - 如何從數據庫中使用HBM文件映射

<property name="ContactId" length="4" /> 
<many-to-one 
    name="DefaultContact" 
    column="ContactId" 
    class="Models.Contact" 
    update="false" 
    insert="false"/> 
獲取從數據庫中的數據對象

此代碼是正確的獲取數據,但現在我需要獲取有條件像我有以下特性和HBM文件MANT-to-one元素的數據.....

<property name="ParentId" length="4" /> 
<property name="ParentType" length="4" /> 
<many-to-one 
     name="ContactParent" 
     column="???????? ParentId which could be CustomerId or ProspectId or LeadId according to Parent Type ????????" 
     class="???????? Models.Customer or Models.Prospect or Models.Lead - according to Parent Type ????????" 
     update="false" 
     insert="false"/> 

而且我有根據「父類型」中的值獲取數據pe「屬性,這意味着我需要根據」父類型「 屬性動態地設置」多對一「元素的類屬性。

所以現在,我該如何用多對一的元素或其他方式達到預期的效果......?

在此先感謝。

回答

0

我可以想出兩種方法來處理這個問題。

  1. 不包括ContactParent在模型中,用一個單獨的方法來從ParentType的和的ParentId檢索。

  2. 將所有三個父類型映射爲私有成員,並返回公共屬性中不爲空的那一個。

選項1將是我的第一選擇。

相關問題