我有這樣的域層級:重複類/實體映射錯誤
用戶 - > 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