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 数据。

4

1 回答 1

0

AFAIK你不能。您可以加载映射 xml 并在将其提供给会话工厂之前对其进行更改,或者您可以将其移植到 FluentNHibernate,然后您可以根据需要添加子类。

于 2012-07-02T14:24:04.347 回答