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>

 

 

 

 

 

 

 

 

 

 

posted @ 2012-02-08 13:16  巴别塔  阅读(2442)  评论(0编辑  收藏  举报