1 App.config 的配置:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
    <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler,NHibernate" requirePermission="false"/>
</configSections>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
    <session-factory>
      <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider,NHibernate</property>
      <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
      <property name="connection.connection_string">
        <!--Server=(local);initial catalog=nhibernate;Integrated Security=SSPI-->
        database='nhibernate';server=.;uid='sa';pwd='sa';
      </property>
      <property name="adonet.batch_size">10</property>
      <property name="show_sql">true</property>
      <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
      <property name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property>
    </session-factory>
</hibernate-configuration>
----------------------------------------------------------------------------------------------------------------------

#region 2 。 App.config 配置
            Configuration config = new Configuration().AddAssembly("Test.Model");

factory = config.BuildSessionFactory();
          session = factory.OpenSession(); 
#endregion

--------------------------------------------------------------------------------------------------------------------------
</configuration>

2 web.config的配置 注意 所放字节位置

<!--NHibernate -->
   <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate"/>
   <!--NHibernate-->
</configSections>
<!--NHibernate-->
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
   <session-factory>
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
    <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
    <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
    <property name="connection.connection_string">database='nhibernate';server=.;uid='sa';pwd='sa';</property>
    <property name="show_sql">true</property>
    <property name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property>
   </session-factory>
</hibernate-configuration>
<!--NHibernate-->
<appSettings/>

---------------------------------------------------------------------------------------------------------

#region 2、利用web.config 配置 通过

//NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration().AddAssembly("Test.Model");
        //factory = config.BuildSessionFactory();
        //session = factory.OpenSession();

#endregion

-----------------------------------------------------------------------------------------------------------

3 NHibernate.cfg.xml 配置:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-mapping-2.2">
<session-factory xmlns="urn:nhibernate-configuration-2.2">
    <!-- properties -->
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
    <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
    <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
    <property name="connection.connection_string">database='nhibernate';server=.;uid='sa';pwd='sa';</property>
    <property name="show_sql">true</property>
     <property name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property>
    <property name="use_outer_join">true</property>
    <!-- mapping files -->
    <mapping assembly="Test.Model" />
</session-factory>
</hibernate-configuration>

-------------------------------------------------------------------------------------------------------------------------------------- -----------------------------------------------------------------------------------------------------------------------------------------

#region 3、利用NHibernate.cfg.xml配置

//NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration();
        //config.Configure(@"C:\Documents and Settings\Administrator\桌面\Text\NHibernateTest\WebSite1\NHibernate.cfg.xml");
        //factory = config.BuildSessionFactory();
        //session = factory.OpenSession();
        #endregion

4     创建一个MyConfiguration.cs 结构如下:

public static NHibernate.Cfg.Configuration GetConfig()
    {

NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration();
        config.SetProperty("hibernate.connection.provider", "NHibernate.Connection.DriverConnectionProvider");
        config.SetProperty("hibernate.connection.driver_class", "NHibernate.Driver.SqlClientDriver");
        config.SetProperty("hibernate.connection.connection_string", "database='nhibernate';server=.;uid='sa';pwd='sa';");
        config.SetProperty("hibernate.dialect", "NHibernate.Dialect.MsSql2005Dialect,NHibernate");
        config.SetProperty("hibernate.use_outer_join", "true");
        config.SetProperty("hibernate.show_sql", "false");
        config.SetProperty("proxyfactory.factory_class", "NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu");
        config.AddAssembly("Test.Model");
        return config;
      
    }

------------------------------------------------------------------------------------------------------------------------------

#region 4、使用MyConfiguration.cs配置

//NHibernate.Cfg.Configuration config = MyConfiguration.GetConfig();//使用MyConfiguration.cs
        //factory = config.BuildSessionFactory();
        factory = MyConfiguration.GetConfig().BuildSessionFactory();
        session = factory.OpenSession(); 
        #endregion

Nhibernate 三种配置方式的更多相关文章

  1. tomcat下jndi的三种配置方式

    jndi(Java Naming and Directory Interface,Java命名和目录接口)是一组在Java应用中访问命名和目录服务的API.命名服务将名称和对象联系起来,使得我们可以用 ...

  2. IIS下PHP的三种配置方式比较

    在Windows IIS 6.0下配置PHP,通常有CGI.ISAPI和FastCGI三种配置方式,这三种模式都可以在IIS 6.0下成功运行,下面我就讲一下这三种方式配置的区别和性能上的差异. 1. ...

  3. 【转】tomcat下jndi的三种配置方式

    jndi(Java Naming and Directory Interface,Java命名和目录接口)是一组在Java应用中访问命名和目录服务的API.命名服务将名称和对象联系起来,使得我们可以用 ...

  4. 【jdbc】【c3p0】c3p0三种配置方式【整理】

    c3p0三种配置方式 c3p0的配置方式分为三种,分别是1.setters一个个地设置各个配置项2.类路径下提供一个c3p0.properties文件3.类路径下提供一个c3p0-config.xml ...

  5. spring Bean的三种配置方式

    Spring Bean有三种配置方式: 传统的XML配置方式 基于注解的配置 基于类的Java Config 添加spring的maven repository <dependency> ...

  6. Hive metastore三种配置方式

    http://blog.csdn.net/reesun/article/details/8556078 Hive的meta数据支持以下三种存储方式,其中两种属于本地存储,一种为远端存储.远端存储比较适 ...

  7. c3p0三种配置方式(automaticTestTable)

    c3p0的配置方式分为三种,分别是http://my.oschina.net/lyzg/blog/551331.setters一个个地设置各个配置项2.类路径下提供一个c3p0.properties文 ...

  8. MyEclipse中web服务器的三种配置方式

    初学Javaweb开发的人们都会遇到一个问题,就是服务器环境的搭建配置问题.下面介绍三种服务器的搭建方式. 直接修改server.xml文件 当你写了一个web应用程序(jsp/servlet),想通 ...

  9. 【c3p0】 C3P0的三种配置方式以及基本配置项详解

    数据库连接池C3P0框架是个非常优异的开源jar,高性能的管理着数据源,这里只讨论程序本身负责数据源,不讨论容器管理. ---------------------------------------- ...

随机推荐

  1. PHPstudy如何在本地搭建多站点

    参考地址: http://jingyan.baidu.com/article/e52e36154227ef40c70c5147.html

  2. R语言数据分析系列之四

    R语言数据分析系列之四 -- by comaple.zhang 说到统计分析我们就离不开随机变量,所谓随机变量就是数学家们为了更好的拟合现实世界的数据而建立的数学模型.有了她我们甚至能够来预測一个站点 ...

  3. php修改密码

      为了让页面更为好看一些,我一般会选择bootstrap,写起来虽然看着麻烦,但是我们真正需要的只有中间的内容  下面是html的内容 <div id="tbx"" ...

  4. 网络编程------socketserver模块以及socket模块的更多用法.

    socketserver模块 内置模块 (其实现原理为并发) socketserver这个模块主要是为了解决: TCP协议中,服务器不能同时连接多个客户端的问题 是处于socket抽象层和应用层之间的 ...

  5. EasyDSS点播与直播服务器软件-二次开发接口对接说明示列

    EasyDSS流媒体服务器软件,提供一站式的转码.点播.直播.时移回放服务,极大地简化了开发和集成的工作.其中,点播版本主要包含:上传.转码.分发.直播版本,主要包含:直播.录像, 直播支持RTMP输 ...

  6. EasyDSS流媒体解决方案实现的实时数据统计报表、视频文件上传、点播、分享、集成代码等功能

    之前的EasyDSS作为rtmp流媒体服务器自从推出就备受用户好评,随着用户的需求的变更产品自身的发展是必须的: 为了更好的用户体验和和功能的完善,我们在EasyDSS的基础上增添了服务器硬件数据报表 ...

  7. php自定义函数: amr转mp3格式

    <?php function amr2mp3($file){ if (file_exists($file . '.mp3') == true) { return; } else { $param ...

  8. unity里standard pbr(一)

    关注forwardbase下的 standard.shader #pragma vertex vertBase #pragma fragment fragBase #include "Uni ...

  9. python3保存一个网页

    import requests res = requests.get("http://www.baidu.com") savefile = open("baidu.htm ...

  10. 免费好用的Diff和Merge工具大总结

    总结:比较下来:diffmerge和P4merge最好用,kdiff比较专业些,支持自动merge. 一 csdiff 下载:http://www.componentsoftware.com/Prod ...