2009-09-29 216 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

重複類/實體映射常常觸發。

相關問題