2009-09-29 238 views
1

我有这样的域层级:重复类/实体映射错误

用户 - > 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.CanConfirmData­baseMatchesMappings: 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 类有问题。我不确定是什么导致重复的类/实体映射。 任何想法?

谢谢。

+0

您确定即使使用此“简化”代码也会遇到此问题吗?也许你已经优化了这个问题...... – 2009-09-29 14:39:04

+0

我还能遗漏什么?我遗漏了一些属性来缩短问题。但关键部分在那里。谢谢。 – Roger 2009-09-29 15:08:28

+0

我的意思是,你会得到FluentNHibernate异常,但是代码中没有任何关于FNH的内容。我只是问你是否真的可以用简化的代码重现问题,或者只是猜测。如果你不能解释一个问题,你永远不应该猜测什么是关键。 – 2009-09-29 15:18:11

回答

1

您需要在您的项目中更改IsBaseType输入。其他信息你可以找到here

希望它会有所帮助。如果你复制粘贴&你* .hbm文件和忘记更改你的name属性的值相同的

所以两个* .hbm文件

+0

感谢您的其他信息。我以前见过。我如何在HBM上做到这一点?我在这里不使用流利NHibernate。 – Roger 2009-09-29 15:03:37

+0

感谢您的指导。我一直在使用夏普体系结构。默认情况下,它使用Fluent NHibernate。但我最近在自动映射中遇到了一个错误。所以,我转而使用HBM来解决这个问题。从那以后,我习惯了那些我忘记Fluent NHibernate惯例的hbm文件。你是对的。我错过了IsBaseType传送。 – Roger 2009-09-29 15:35:54

0

重复类/实体映射常常触发。