NHibernate 数据库支持分类配置

php中文网
发布: 2016-06-07 14:59:35
原创
1529人浏览过

nhibernate is primarily tested on microsoft sql server 2000. it is also known to work on these databases: Microsoft SQL Server 2005/2000 Oracle Microsoft Access Firebird PostgreSQL DB2 UDB MySQL SQLite Microsoft SQL Server 2005/2000 SQL Se

nhibernate is primarily tested on microsoft sql server 2000. it is also known to work on these databases:

    • Microsoft SQL Server 2005/2000
    • Oracle
    • Microsoft Access
    • Firebird
    • PostgreSQL
    • DB2 UDB
    • MySQL
    • SQLite

Microsoft SQL Server 2005/2000

SQL Server 2005 and 2000 are the primary databases used by the developers of NHibernate.

Configuration example:

<code jive-xml=""><?xml version="1.0" ?><br /><hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" ><br />    <session-factory><br />        <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property><br />        <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property><br />        <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property><br />        <property name="connection.connection_string">Server=(local);Initial Catalog=dbname;User Id=user;Password=********</property><br />    </session-factory><br /></hibernate-configuration><br /></code>
登录后复制

For SQL Server 2000, change the dialect to NHibernate.Dialect.MsSql2000Dialect.

Issues

SQL Server sometimes ignores columns specified in ORDER BY clause of a query if they are not included in the SELECT clause. This behavior is actually valid according to the SQL standard, but may be surprising. For example, a query like this is not guaranteed to be ordered correctly:

from Person p order by p.Company.Name<br />
登录后复制


Oracle

Oracle 9i and 10g are supported, both using Microsoft driver (System.Data.OracleClient) and using Oracle driver (Oracle.Data.OracleClient).

Issues

Microsoft's driver does not handle long character strings correctly. An error happens in some circumstances when using a string of length 2000-4000 as a parameter value.

Oracle cannot handle empty strings (""), you should use null instead. An IUserType implementation to perform the conversion is contained in Nullables.NHibernate library (part of NHibernateContrib package).



Microsoft Access

Microsoft Access has its own dialect and driver (contributed by Lukas Krejci).

They are currently in a separated library: NHibernate.JetDriver.dll (in NHibernateContrib package).

Here is what your hibernate.cfg.xml file should contain when using a Microsoft Access database:

<code jive-xml=""><?xml version="1.0" ?><br /><hibernate-configuration  xmlns="urn:nhibernate-configuration-2.2" ><br />    <session-factory><br />        <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property><br />        <property name="dialect">NHibernate.JetDriver.JetDialect, NHibernate.JetDriver</property><br />        <property name="connection.driver_class">NHibernate.JetDriver.JetDriver, NHibernate.JetDriver</property><br />        <property name="connection.connection_string">Provider=Microsoft.Jet.OLEDB.4.0;Data Source=YourDatabaseFilePathHere.mdb</property><br />    </session-factory><br /></hibernate-configuration><br /></code>
登录后复制

Issues

There are still few problems with join syntax in queries that use more than one join. This driver passes 93% of NHibernate tests (there are 23 failing tests).

The most complete topic about these issues is here: Using NHibernate with Microsoft Access 2003 / Jet 4.0. JIRA issues NH-124 and NH-437 have some information on problems with implementing Microsoft Access dialect. You can also try searching NHibernate forum for "access jet" (require all words).



Firebird

Firebird is supported since version 1.5.3, though version 2.0.1 is strongly recommended. To work with Firebird, install the latest Firebird .NET Data Provider. If the data provider is installed in the GAC (the standard behavior of its installer), add this div to your application configuration file (App.config or Web.config):

多多淘宝客
多多淘宝客

安装环境: php5.2+mysql5.x 以上;Zend版本: Zend Optimizer 3.3.0 或以上版本最少配置 200M+20Mmysql;推荐配置:大于500M空间+大于50M数据库。 站长要求:网络建站初学者及更高级站长。网站管理要求:一天在线5小时左右(主要为了在线客服,邮件或电话服务可忽略),管理时间30分钟左右(做提现审核及支付处理,适当增加文章发布等)。适合环境:单独建

多多淘宝客 0
查看详情 多多淘宝客
<code jive-xml=""><runtime><br />    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"><br />        <qualifyAssembly partialName="FirebirdSql.Data.FirebirdClient"<br />            fullName="FirebirdSql.Data.FirebirdClient, Version=2.0.1.0, Culture=neutral, PublicKeyToken=3750abcc3150b00c" /><br />    </assemblyBinding><br /></runtime><br /></code>
登录后复制

The value of the fullName attribute will depend on the version of the assembly you have installed in the GAC.

Here is what your hibernate.cfg.xml file should contain when using Firebird:

<code jive-xml=""><hibernate-configuration  xmlns="urn:nhibernate-configuration-2.2" ><br />    <session-factory name="NHibernate.Test"><br />        <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property><br />        <property name="connection.driver_class">NHibernate.Driver.FirebirdClientDriver</property><br />        <property name="connection.isolation">ReadCommitted</property><br />        <property name="connection.connection_string"><br />            Server=localhost;<br />            Database=C:\nhibernate.fdb;<br />            User=SYSDBA;Password=masterkey<br />        </property><br />        <property name="show_sql">false</property><br />        <property name="dialect">NHibernate.Dialect.FirebirdDialect</property><br />        <property name="use_outer_join">true</property><br />        <property name="command_timeout">444</property><br />        <property name="query.substitutions">true 1, false 0, yes 1, no 0</property><br />    </session-factory><br /></hibernate-configuration><br /></code>
登录后复制

All Firebird 2.0.1 embedded functions are registered in the dialect, as well as user-defined functions from ib_udf2.sql. These functions can be used in HQL queries.



PostgreSQL

PostgreSQL version 7.4 with latest Npgsql works almost perfectly. Later versions should work too.

Configuration example:

<code jive-xml=""><?xml version="1.0" encoding="utf-8"?><br /><hibernate-configuration  xmlns="urn:nhibernate-configuration-2.2" ><br />    <session-factory name="NHibernate.Test"><br />        <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property><br />        <property name="connection.driver_class">NHibernate.Driver.NpgsqlDriver</property><br />        <property name="connection.connection_string"><br />            Server=localhost;initial catalog=nhibernate;User ID=nhibernate;Password=********;<br />        </property><br />        <property name="dialect">NHibernate.Dialect.PostgreSQLDialect</property><br />    </session-factory><br /></hibernate-configuration><br /></code>
登录后复制


DB2 UDB

DB2 UDB is supported and reportedly even passes all the tests (see http://nhibernate.sourceforge.net/forum/viewtopic.php?t=73). Example configuration using the ODBC drivers that come with the 'stinger' release of db2:

<code jive-xml=""><?xml version="1.0" encoding="utf-8" ?><br /><hibernate-configuration xmlns="urn:nhibernate-configuration-2.0" ><br /><br />    <session-factory name="session"><br /><br />        <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property><br />        <property name="connection.driver_class">NHibernate.Driver.OdbcDriver</property><br />        <property name="connection.connection_string">driver={IBM DB2 ODBC DRIVER};Database=db;hostname=host;port=port;protocol=TCPIP; uid=uid; pwd=pwd</property><br />        <property name="show_sql">true</property><br />        <property name="dialect">NHibernate.Dialect.DB2Dialect</property><br />        <property name="use_outer_join">true</property><br /><br />        <mapping resource="..." /><br /><br />    <br />    </session-factory><br /><br /></hibernate-configuration><br /></code>
登录后复制


MySQL

All MySQL versions should work, though there are issues with zero dates (see below for details). To connect to your database use Connector/NET (formerly known as ByteFX.Data.MySqlClient).

Configuration example:

<code jive-xml=""><?xml version="1.0" encoding="utf-8"?><br /><hibernate-configuration  xmlns="urn:nhibernate-configuration-2.2" ><br />    <session-factory name="NHibernate.Test"><br />        <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property><br />        <property name="connection.driver_class">NHibernate.Driver.MySqlDataDriver</property><br />        <property name="connection.connection_string"><br />            Database=test;Data Source=someip;User Id=blah;Password=blah<br />        </property><br />        <property name="dialect">NHibernate.Dialect.MySQLDialect</property><br />    </session-factory><br /></hibernate-configuration><br /></code>
登录后复制

Issues

MySQL has a unique "feature" of allowing invalid dates in a DATE field, and especially using 0000-00-00 as a default value for DATE NOT NULL columns. When MySQL Connector encounters such a date, it either throws an exception or returns a non-standard MySqlDateTime object (depending on a connection string parameter) which throws an exception when converting itself to a DateTime.

Possible workarounds:

  • avoid zero dates
  • modify Connector/NET source code to round zero dates to DateTime.Min and back (see JIRA issue NH-32 for a patch to an older version of the Connector)
  • create a user type for MySqlDateTime (no known implementations currently)


SQLite

SQLite version 3 works rather well using ADO.NET provider available from http://sourceforge.net/projects/adodotnetsqlite. NHibernate Query Analyzer uses SQLite (see [Related Projects]).

Configuration example:

<code jive-xml=""><?xml version="1.0" encoding="utf-8"?><br /><hibernate-configuration  xmlns="urn:nhibernate-configuration-2.2" ><br />    <session-factory name="NHibernate.Test"><br />        <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property><br />        <property name="connection.driver_class">NHibernate.Driver.SQLiteDriver</property><br />        <property name="connection.connection_string"><br />            Data Source=nhibernate.db;Version=3<br />        </property><br />        <property name="dialect">NHibernate.Dialect.SQLiteDialect</property><br />        <property name="query.substitutions">true=1;false=0</property><br />    </session-factory><br /></hibernate-configuration><br /></code>
登录后复制

Issues

SQLite currently fails 17 tests out of approximately 500 in NHibernate test suite. Some of the failures are caused by SQLite being unable to store strings containing NUL characters, other tests fail because of a bug in SQLite ADO.NET provider when using a table with spaces in its name.

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号