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>

  • 相关阅读:
    cocos2d-x lua 学习笔记(1) -- 环境搭建
    Cocos2d-x 3.x 如何编译成安卓程序
    Cocos2d-x 3.4 初体验——安装教程
    cocos2d-x 之 CCProgressTimer
    android sdk离线安装
    在cocos2d-x-3.0 android 平台编译时提示CocosGUI.h: No such file or directory
    cocos2d_x iconv转码
    cocos2d-x发生undefined reference to `XX'异常 一劳永逸解决办法
    libjpeg.a exists or that its path is correct
    UE4插件
  • 原文地址:https://www.cnblogs.com/babietongtianta/p/2342543.html
Copyright © 2011-2022 走看看