重复类/实体映射错误
我有这样的域层级:重复类/实体映射错误
用户 - > EntityWithAuditDate - >实体
这里是域:(简化的)
public class User : EntityWithAuditDate
{
public User(){}
public virtual string Name { get; set; }
}
public abstract class EntityWithAuditDate : Entity
{
public EntityWithAuditDate() { }
public virtual DateTime? CreatedAt { get; set; }
}
和映射(简化的):
<class name="User" table="Users" abstract="false">
<id name="Id" type="Int32" column="UserId">
<generator class="identity" />
</id>
<property name="Name" type="String"/>
<property name ="CreatedAt"/>
</class>
当我跑了mapping integration unit test,我 这个错误:
Tests.AltNetTime.Data.NHibernateMaps.MappingIntegrationTests.CanConfirmDatabaseMatchesMappings: FluentNHibernate.Cfg.FluentConfigurationException : An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
Database was not configured through Database method.
----> FluentNHibernate.Cfg.FluentConfigurationException : An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
Database was not configured through Database method.
----> NHibernate.MappingException : Could not compile the mapping document: (XmlDocument) ----> NHibernate.DuplicateMappingException : Duplicate class/entity mapping AltNetTime.Core.User TearDown : System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation. ----> System.Collections.Generic.KeyNotFoundException : The given key was not present in the dictionary.
如果用户类从实体继承而来,则传递单元测试。 此外,我不得不从映射文件中删除CreatedAt属性。 显然,EntityWithAuditDate 类有问题。我不确定是什么导致重复的类/实体映射。 任何想法?
谢谢。
重复类/实体映射常常触发。
您确定即使使用此“简化”代码也会遇到此问题吗?也许你已经优化了这个问题...... – 2009-09-29 14:39:04
我还能遗漏什么?我遗漏了一些属性来缩短问题。但关键部分在那里。谢谢。 – Roger 2009-09-29 15:08:28
我的意思是,你会得到FluentNHibernate异常,但是代码中没有任何关于FNH的内容。我只是问你是否真的可以用简化的代码重现问题,或者只是猜测。如果你不能解释一个问题,你永远不应该猜测什么是关键。 – 2009-09-29 15:18:11