0

Is it possibly to use a mapping from a referenced assembly as a base for a new mapping?

The reasoning behind this is there are general objects many applications use, thus they reference the CentralDataLayer.dll. The issue is some applications have additional tables that are relational to tables from the CentralDataLayer. So I want to be able to extend these mapping from these applications.

The referenced base mapping looks as it normally would:

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

The next a mapping file is the one I'm unsure about:

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

And the resulting class for the NHibernate.Map.WIP.Employee mapping would be:

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

Now the developer should be able to use NHibernate.Map.WIP.Employee in there project with the connected NHibernate.Map.Employee Data.

roydukkey
  • 3,149
  • 2
  • 27
  • 43

1 Answers1

0

AFAIK you can't. you could load the mapping xml and alter it befor feeding it to the session factory or you could port it to FluentNHibernate and then you can add subclasses as long as you want.

Firo
  • 30,626
  • 4
  • 55
  • 94