是否可以使用引用的程序集中的映射作为新映射的基础?
这背后的原因是许多应用程序都使用通用对象,因此它们引用了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数据。
答案 0 :(得分:0)
AFAIK你不能。您可以加载映射xml并将其更改为将其提供给会话工厂,或者您可以将其移植到FluentNHibernate,然后您可以根据需要添加子类。