zoukankan      html  css  js  c++  java
  • NHibernate(3)hibernate.cfg.xml 配置

    1、MYSQL5  数据库

    <?xml version="1.0" encoding="utf-8" ?>
    <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    <session-factory name="NHibernate.Test">
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
    <property name="connection.driver_class">NHibernate.Driver.MySqlDataDriver</property>
    <property name="connection.connection_string">Server=192.168.0.2;Port=3306;Database=SampeDataBase;User ID=root;Password=root;CharSet=utf8</property>
    <property name="dialect">NHibernate.Dialect.MySQL5Dialect</property>
    <property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
    <property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>
    <property name="hbm2ddl.keywords">none</property>
    <mapping assembly="XXXX.Infrastructure.Entities"/>
    </session-factory>
    </hibernate-configuration>

    尤其要强调的是 <property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>

    在数据表设计中如果采用了 bit 类型的字段,并且对应了业务类中类型为 bool 值,一定要如上设置下。

    2、MSSQL  数据库

    <?xml version="1.0" encoding="utf-8"?>
    <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
    <session-factory name="NHibernate.Test">
    <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
    <property name="connection.connection_string">
    Data Source=192.168.0.2,1433;Initial Catalog=SampeDataBase;
    Integrated Security=False;User Id=sa;Password=;
    </property>
    <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
    <property name="proxyfactory.factory_class"> NHibernate.ByteCode.Castle.ProxyFactoryFactory,NHibernate.ByteCode.Castle</property>
    <property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>
    <mapping assembly="XXXX.Infrastructure.Entities"/>
    </session-factory>
    </hibernate-configuration>

    mssql 不同的版本有时需要修改下属性 dialect (方言)

    上面是 ms sql 2005 的配置,在使用 sql 2000 时有方法会出错(比如分页)

    ms sql 2000 的配置

    <property name="dialect">NHibernate.Dialect.MsSql2000Dialect</property>

  • 相关阅读:
    4.qml-ECMAScript(Array对象、Math对象)
    3.qml-ECMAScript_03(Object基类对象、String对象)
    2.qml-ECMAScript_02(原始值类型、通用转换方法)
    ORA-00001: 违反唯一约束条件(SOLEX.SYS_C0012537) --解决方法
    macOS 系统打开和退出文件夹(cd命令)
    macOS 系统下node安装和环境配置(通过node官网)
    macOS 系统报错:zsh:command not found :npm
    macOS 系统更新node老是不成功
    macOS 系统上升级 Python
    maxOS 系统更新node版本
  • 原文地址:https://www.cnblogs.com/babietongtianta/p/2342543.html
Copyright © 2011-2022 走看看