[英]Using a nHibernate wrapper with fluent nHibernate
是否可以使用這種具有流暢配置的包裝器?
http://jeffreypalermo.com/blog/use-this-nhibernate-wrapper-to-keep-your-repository-classes-simple/
如果是這樣,我將在哪里添加流暢的配置?
此外,這是否適合在asp.net和Windows應用程序中使用? 我打算使用存儲庫模式,以此來創建我的nHibernate會話?
在SessionBuilder
的GetConfiguration
方法中,而不是
public Configuration GetConfiguration()
{
var configuration = new Configuration();
configuration.Configure();
return configuration;
}
顯示在您鏈接的頁面中,只需執行以下操作:
public Configuration GetConfiguration()
{
return Fluently.Configure()
.Database(/* your database settings */)
.Mappings(/* your mappings */)
.ExposeConfiguration(/* alter Configuration */) // optional
.BuildConfiguration();
}
關於對上下文的進一步查詢,您將擁有兩個繼承ISessionBuilder
類,例如AspSessionBuilder
和WinAppSessionBuilder
,並為當前項目注入適當的類。 您應該使用Jamie Ide概述的策略(也作為對此問題的答案)發布來處理上下文,而不要使用HttpContext
。 您只需要修改以下行:
.ExposeConfiguration(x => x.SetProperty("current_session_context_class", "web")
類似於"call"
或"thread_static"
。 有關不同上下文會話類型的詳細說明,請參見NHibernate Forge Wiki上的此頁面:
是的,您可以使用它,但是最好使用NHibernate的內置上下文會話管理,而不是自己處理。 請參閱我對這個問題的回答 。 除了減少編碼外,它還提供了除HttpContext之外的兩個其他選項:Call和ThreadStatic。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.