2012-06-29 201 views
0

是否可以使用來自引用程序集的映射作爲新映射的基礎?如何將映射作爲基礎添加到新映射中?

這背後的原因是,有一般的對象許多應用程序使用,因此,他們引用CentralDataLayer.dll。問題是一些應用程序具有與CentralDataLayer中的表相關的附加表。所以我想能夠從這些應用程序中擴展這些映射。

所參考的基礎測繪看起來象通常那樣:

<?xml version="1.0" encoding="utf-8" ?> 
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="CentralDataLayer" namespace="NHibernate.Map"> 
    <class name="NHibernate.Map.Employee, CentralDataLayer" table="`wt_employee`" schema="`wt_global`"> 

     <id name="Id" column="`emp_id`" type="Int32" unsaved-value="0"> 
      <generator class="native" /> 
     </id> 

     <property name="Number" column="`emp_number`" type="Int32" not-null="true" /> 
     <property name="Email" column="`email`" type="String" length="100" /> 
     <property name="IsFullTime" column="`is_full_time`" type="Boolean" not-null="true" /> 
     <property name="HireDate" column="`hire_date`" type="Date" /> 

     <property name="SsnSerialNumber" column="`last4ssn`" type="String" lazy="true" /> 

     <property name="OfficePhone" column="`work_phone`" type="String" length="10" /> 
     <property name="OfficeExtension" column="`work_phone_extn`" type="String" length="5" /> 

     <component name="UpdateRecord" class="NHibernate.Map.Component.UpdateRecord, CentralDataLayer"> 
      <property name="Date" column="`updated_dt`" type="Date" /> 
      <property name="By" column="`updated_by`" type="String" length="60" /> 
     </component> 

     <many-to-one name="User" column="`user_id`" class="NHibernate.Map.User, CentralDataLayer" unique="true" /> 
     <many-to-one name="Job" column="`job_id`" class="NHibernate.Map.Job, CentralDataLayer" /> 

    </class> 
</hibernate-mapping> 

下一個映射文件是一個我不確定:

<?xml version="1.0" encoding="utf-8" ?> 
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="DataLayer" namespace="NHibernate.Map.WIP" auto-import="false"> 
    <class name="NHibernate.Map.WIP.Employee, DataLayer" table="`wt_employee`" schema="`wt_wip`"> 

     <!-- Logically I would do something like this. --> 
     <include class="NHibernate.Map.Employee" table="`wt_employee`" schema="`wt_global`" /> 

     <property name="Active" column="`emp_active`" type="Boolean" not-null="true" /> 
     <property name="DashboardColumnAmount" column="`emp_dashboard_col_amount`" type="Byte" not-null="true" /> 

    </class> 
</hibernate-mapping> 

而對於NHibernate的結果類。 Map.WIP.Employee映射將是:

namespace NHibernate.Map.WIP 
{ 
    public class Employee : Map.Employee 
    { 
     #region Fields 

     private bool _active; 
     private byte _dashboardColumnAmount; 

     #endregion Fields 

     #region Properties 

     public virtual bool Active 
     { 
      get { return _active; } 
      set { _active = value; } 
     } 
     public virtual byte DashboardColumnAmount 
     { 
      get { return _dashboardColumnAmount; } 
      set { _dashboardColumnAmount = value; } 
     } 

     #endregion Properties 
    } 
} 

現在開發人員應該能夠使用NHibernate。 Map.WIP.Employee在那裏有連接的NHibernate.Map.Employee Data的項目。

+0

爲什麼不把它映射爲員工的子類? – Firo

+0

如何在不觸及NHibernate.Map.Employee映射的情況下執行此操作? – roydukkey

回答

0

AFAIK你不能。您可以加載映射xml並將其更改爲將其提供給會話工廠,或者將其移植到FluentNHibernate,然後可以隨意添加子類。

相關問題