NHibernate在单独的程序集中加入了子类

Not*_*elf 8 nhibernate orm fluent-nhibernate

我有以下解决方案项目结构:

Application.Core.Entities

Application.Xtend.CustomerName.Entities

在核心项目中,我有一个实体客户指责.在XTend项目中,我定义了一个实体,它将Customer子类命名为xCustomer(此时缺少更好的名称......).

这里的想法是我们的​​应用程序中有一个Core域模型.然后,客户可以创建一个包含核心模型扩展的新程序集.当扩展程序集存在时,智能IRepository类将返回核心类的子类.

我试图在NHibernate中映射这种关系.使用Fluent NHibernate我能够生成这个映射:

<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                   default-lazy="false"
                   assembly="NHibernate.Core.Entites"
                   namespace="NHibernate.Entites"
                   default-access="field.camelcase-underscore">
  <!-- Customer is located in assembly Application.Core.Entities -->
  <class name="Customer" table="Customers" xmlns="urn:nhibernate-mapping-2.2">
    <id name="Id" column="Id" type="Int64">
      <generator class="native" />
    </id>
    <component name="Name" insert="true" update="true">
      <property name="LastName" column="LastName" length="255" type="String" not-null="true">
        <column name="LastName" />
      </property>
      <property name="FirstName" column="FirstName" length="255" type="String" not-null="true">
        <column name="FirstName" />
      </property>
    </component>
    <!-- xCustomer is located in assembly Application.XTend.CustomerName.Entities -->
    <joined-subclass name="xCustomer" table="xCustomer">
      <key column="CustomerId" />
      <property name="CustomerType" column="CustomerType" length="255" type="String" not-null="true">
        <column name="CustomerType" />
      </property>
    </joined-subclass>
  </class>
</hibernate-mapping>
Run Code Online (Sandbox Code Playgroud)

但是NHib会抛出以下错误:

NHibernate.MappingException:持久化类Application.Entites.xCustomer,找不到Application.Core.Entites ---> System.TypeLoadException:无法从程序集'Application.Core.Entites,Version = 1.0加载类型'Application.Entites.xCustomer' .0.0,Culture = neutral,PublicKeyToken = null'..

哪个有意义xCustomer未在Core库中定义.

是否可以跨越这样的不同组件?我接近这个问题了吗?

Not*_*elf 7

我在NHibernate Users邮件列表上问了同样的问题,解决方案非常明显,我有点尴尬,我看不到它.

hibernate-mapping属性程序集和命名空间是方便的快捷方式,允许您不必完全限定类名.这使您可以获得良好的标记,但类和连接子类元素的name属性也可以采用完全限定的程序集名称.

所以上面破坏的映射文件可以像这样修复:

<joined-subclass name="Application.XTend.CustomerName.Entities.xCustomer, 
                 Application.XTend.CustomerName.Entities, Version=1.0.0.0, 
                 Culture=neutral, PublicKeyToken=null" 
                 table="xCustomer">
  <key column="CustomerId" />
  <property name="CustomerType" column="CustomerType" length="255" 
            type="String" not-null="true">
    <column name="CustomerType" />
  </property>
</joined-subclass>
Run Code Online (Sandbox Code Playgroud)

这符合我的预期.然后,我看了一下Fluent-NHibernate源代码并创建了一个补丁,其中包含工作单元测试以解决问题并将其提交给项目.

谢谢你帮助@David Kemp