blogjava's web log

          blogjava's web log
          ...

          Nhibernate隨記

          在asp.net中.配置.NHibernate文件 ,
          web.xml

          ?? < configSections >
          ????
          < section? name ="nhibernate" ?type ="System.Configuration.NameValueSectionHandler,?System,?Version=1.0.5000.0,Culture=neutral,?PublicKeyToken=b77a5c561934e089" /> ?
          ??
          </ configSections >
          ??
          ??
          < nhibernate >
          ????
          < add? key ="hibernate.connection.provider" ?value ="NHibernate.Connection.DriverConnectionProvider" />
          ????
          < add? key ="hibernate.prepare_sql" ?value ="true" />
          ????
          < add? key ="hibernate.cache.provider_class" ?value ="NHibernate.Caches.SysCache.SysCacheProvider,?NHibernate.Caches.SysCache" />
          ????
          < add? key ="hibernate.cache.use_query_cache" ?value ="true" />
          ????
          < add? key ="relativeExpiration" ?value ="30" />
          ????
          < add? key ="hibernate.dialect" ?value ="NHibernate.Dialect.MsSql2000Dialect" />
          ????
          < add? key ="hibernate.connection.driver_class" ?value ="?NHibernate.Driver.MySqlDataDriver" />
          ????
          < add? key ="hibernate.connection.connection_string" ?value ="Server=localhost;database=northwind;uid=sa;pwd=" />
          ????
          <!-- ?add?key="hibernate.connection.connection_string"?value="Server=localhost;database=mysql;uid=root;pwd="/ -->
          ??
          </ nhibernate >
          ??


          asp.net 中Nhibernate Session 管理..

          using?System;
          using?System.Data;
          using?System.Configuration;
          using?System.Web;
          using?System.Web.Security;
          using?System.Web.UI;
          using?System.Web.UI.WebControls;
          using?System.Web.UI.WebControls.WebParts;
          using?System.Web.UI.HtmlControls;
          using?Ibatis.common;
          namespace?WebApplication1
          {
          ????
          public?class?NHSessionModule?:?IHttpModule
          ????
          {
          ????????
          public?void?Init(HttpApplication?context)
          ????????
          {
          ????????????context.BeginRequest?
          +=?new?EventHandler(Context_BeginRequest);
          ????????????context.EndRequest?
          +=?new?EventHandler(Context_EndRequest);
          ????????}

          ????????
          public?void?Dispose()
          ????????
          {
          ????????????
          //?Nothing?here????
          ????????}

          ????????
          private?void?Context_BeginRequest(object?sender,?EventArgs?e)
          ????????
          {
          ???????????
          ????????????
          ????????????
          if?(!HttpContext.Current.Request.AppRelativeCurrentExecutionFilePath.ToUpper().EndsWith(".ASPX"))
          ?????????????
          return;
          ??//?創(chuàng)建Nhibernate Session??????HttpContext.Current.Items.Add("nhsession",?ss);

          ????????}


          ????????
          private?void?Context_EndRequest(object?sender,?EventArgs?e)
          ????????
          {
          ???????????
          if?(!HttpContext.Current.Request.AppRelativeCurrentExecutionFilePath.ToUpper().EndsWith(".ASPX"))
          ???????????????
          return;
          ????????????????????? //銷毀
          ??????????//??INHSessionManager?mgr?
          =?(INHSessionManager)MindDumpContainer.GetInstance().GetObject(typeof(INHSessionManager));
          ?????????//???mgr.Drop();
          ????????}

          ????}

          ????
          }


          配置文件
          ???<httpModules>

          ????????
          <add?type="WebApplication1.NHSessionModule"?name="NHSessionModule"/>
          ??????
          </httpModules>

          3:

          ???加載 hbm.xml 實體

          ??? public NHSession()
          ?????? {
          ?????????? cfg = new Configuration();
          ??????????
          ?????????? foreach (string? entityName in 實體 程序集名稱)
          ?????????? {
          ?????????????? cfg.AddAssembly(entityName.Trim());
          ?????????? }
          ?????????
          ?????????????? factory = cfg.BuildSessionFactory();
          ??????
          ?????? }


          posted on 2006-08-02 10:09 record java and net 閱讀(936) 評論(0)  編輯  收藏 所屬分類: javadot net相關

          導航

          常用鏈接

          留言簿(44)

          新聞檔案

          2.動態(tài)語言

          3.工具箱

          9.文檔教程

          友情鏈接

          搜索

          最新評論

          主站蜘蛛池模板: 安福县| 武冈市| 新密市| 察哈| 芒康县| 邢台市| 兰溪市| 保康县| 潜江市| 商水县| 凤凰县| 闽侯县| 武冈市| 阿拉善右旗| 蓝田县| 亳州市| 寿阳县| 英吉沙县| 鄂州市| 潼关县| 永和县| 达州市| 公主岭市| 紫阳县| 彭水| 凤台县| 宜城市| 海丰县| 泸州市| 台中县| 辽宁省| 奈曼旗| 绥中县| 金山区| 宁波市| 曲阜市| 郓城县| 大石桥市| 左云县| 乌拉特前旗| 沙洋县|