开发者

how can i setup my nhibernate library to work in both a web and console application?

on the web application, I am using a NHibernate helper that looks up the sessi开发者_如何学Con that was opened in a httpmodule (and committed there also).

  <property name="current_session_context_class">web</property>

In the console application, what do I do?


Your options are: "call" & "thread_static". Have a look at this for more detailed explanation on all available contexts:

http://nhibernate.info/doc/nhibernate-reference/architecture.html#architecture-current-session

In order to have your library work for both a web and a console application you have two options:

  1. Based on a application setting in the App.config and in the web.config have the Session Factory built accordingly by setting the current_session_context_class property manually in the code and remove it from the hibernate.cfg.xml file.
  2. Include a in the web application's web.config and in the app.config of the console application. This way you can have the current_session_context_class property set to different values. If I am not mistaken the in the web.config and in the app.config overrides the values of the hibernate.cfg.xml. If I am wrong then you will just have to include in the web.config and the app.config the complete and remove the hibernate.cfg.xml file from your library.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜