NHibernate的DuplicateMappingException当两个类具有相同的名称,但不同的命名空间 [英] NHibernate DuplicateMappingException when two classes have the same name but different namespaces

查看:406
本文介绍了NHibernate的DuplicateMappingException当两个类具有相同的名称,但不同的命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一类在我的域模型的根,看起来是这样的:

I have a class in my domain model root that looks like this:

namespace Domain
{
  public class Foo { ... }
}

我也有另一个类具有相同名称不同的命名空间:

I also have another class with the same name in a different namespace:

namespace Domain.SubDomain
{
  public class Foo { ... }
}

有关我的映射,我有一个映射有一个名为的子目录子域包含域类映射目录在 Domain.SubDomain 命名空间中。他们都是在同一个组件。

For my mappings, I have a Mapping directory with a subdirectory called SubDomain that contains mappings for the domain classes found in Domain.SubDomain namespace. They are all in the same assembly.

然而,当我尝试加载它们与NHibernate,我不断收到一个 DuplicateMappingException ...即使同时具有FOOS不同的命名空间。在code,我使用加载我的NHibernate的配置是这样的:

However, when I try to load them with NHibernate, I keep getting a DuplicateMappingException... even though both Foos having different namespaces. The code I am using to load my NHibernate configuration is this:

var cfg = new Configuration()
  .Configure()                
  .AddAssembly("Domain");

怎么能告诉NHibernate的让我用两个实体名称相同(但不同的命名空间)?

How can I tell NHibernate to let me use two entities with the same name (but different namespaces)?

推荐答案

我找到了<一href="http://docs.jboss.org/hibernate/stable/core/reference/en/html/mapping.html#mapping-declaration-mapping">answer Hibernate的网站:

I found the answer on the Hibernate website:

如果你有两个持久化类   用相同的不合格的名称,则   应设置自动导入=假。一个   异常会导致如果您尝试   到对应两个类相同   原装进口的名字。

If you have two persistent classes with the same unqualified name, you should set auto-import="false". An exception will result if you attempt to assign two classes to the same "imported" name.

我用的一个属性为&LT;休眠映射&GT; 标签和它的工作

I used that as an attribute for the <hibernate-mapping> tag and it worked.

这篇关于NHibernate的DuplicateMappingException当两个类具有相同的名称,但不同的命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆