我已经开始涉足C#.NET和NHibernate了,我终于陷入了一个我似乎无法弄清楚的例外,谷歌没有帮助.
我得到一个NHibernate.DuplicateMappingException:我的Parent类上的重复类/实体映射.下面是我的父类的映射文件,以及使用Parent类的Youth类:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="Surrix.Cerberus.YouthData"
namespace="Surrix.Cerberus.YouthData.Domain">
<class name="Parent">
<id name="parentId">
<generator class="guid" />
</id>
<property name="firstName" not-null="true" />
<property name="lastName" not-null="true" />
<property name="homePhone" />
<property name="parentEmail" />
<property name="relationshipToYouth" />
<!-- Address component that should map to the Address class -->
<component name="parentAddress">
<property name="street" />
<property name="state" />
<property name="zipCode" />
<property name="city" />
</component>
</class>
</hibernate-mapping>
Run Code Online (Sandbox Code Playgroud)
以下是青年班的相关部分(相当大)
<set name="YouthParents" table="YouthParents" cascade="none">
<key column="youthId" />
<many-to-many column="parentId" class="Parent"/>
</set>
Run Code Online (Sandbox Code Playgroud)
只有其他的东西是Youth类也有firstName和lastName属性,但我看不出这是一个问题.
gra*_*der 15
确保你没有做这两件事.
(1)在代码中添加程序集:
// Code Configuration
var cfg = new Configuration();
cfg.Configure();
cfg.AddAssembly(typeof(Employee).Assembly);
// Presuming Employee resides in "MyAssembly" as seen below.
Run Code Online (Sandbox Code Playgroud)
(2)然后还在配置文件中添加程序集:
<!-- .config configuration -->
<session-factory>
<!-- bunch of other stuff -->
<mapping assembly="MyAssembly"/> <!-- as in MyAssembly.dll -->
</session-factory>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10838 次 |
| 最近记录: |