[英]C# NHibernate mapping
假設我已經流暢地配置了NHibernate
設置,該設置同時使用了Fluent mappings
和Automappings
。
Configuration = Fluently.Configure()
.Database(SQLiteConfiguration.Standard.ShowSql().InMemory)
.Mappings(x =>
{
x.FluentMappings.AddFromAssemblyOf<RepositoryEntity>();
x.AutoMappings.Add(autoPersistenceModel);
});
現在-是否可以檢查某個任意類型T
是否已映射(或未映射)到此配置?
我正在嘗試建立一些防彈庫,我認為這一刻至關重要。
謝謝
是。 創建SessionFactory之后,保留Configuration,並在存儲庫中設置此方法:
public bool IsMapped (Type testType)
{
return MyConfiguration.ClassMappings.Any(m => m.EntityName == testType.FullName);
}
AFAIK可用於檢測流利的和XML映射的類。 如果在不同的命名空間中具有相似名稱的類,則可能需要更緊密地比較,但這應該可以幫助您入門。
您可能還可以在開發“防彈”倉庫中使用的是EntityNotFoundDelegate,它使您可以定義自定義方法來處理提供給沒有映射的存儲庫的實體。 您可能會用它來詢問另一個存儲庫是否可以處理該實體,或將其踢回可能有幾種可能的回購嘗試的Strategy模式。
Keith幾乎回答了您的問題,但是,要獲得更多的防彈效果,可以查看PersistenceSpecification類。 (盡管它需要了解類型T的知識)
http://www.packtpub.com/article/using-fluent-nhibernate-persistence-tester-and-ghostbusters-test
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.