Nhibernate连接各种数据库(转:http://yuguo138.blog.163.com/bl

Microsoft SQL Server 2005/2000

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

Configuration example:

For SQL Server 2000, change the dialect toNHibernate.Dialect.MsSql2000Dialect.

Issues

SQL Server sometimes ignores columns specified inORDER BYclause of a query if they are not included in theSELECTclause. 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.NameOracle

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 yourhibernate.cfg.xmlfile should contain when using a Microsoft Access database:

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 issuesNH-124andNH-437have some information on problems with implementing Microsoft Access dialect. You can also try searching NHibernate forum for "access jet" (require all words).

Firebird

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

<runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <qualifyAssembly partialName="FirebirdSql.Data.FirebirdClient" fullName="FirebirdSql.Data.FirebirdClient, Version=2.0.1.0, Culture=neutral, PublicKeyToken=3750abcc3150b00c" /> </assemblyBinding> </runtime>

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

Here is what yourhibernate.cfg.xmlfile should contain when using Firebird:

<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.FirebirdClientDriver</property> <property name="connection.isolation">ReadCommitted</property> <property name="connection.connection_string"> Server=localhost; Database=C:\nhibernate.fdb; User=SYSDBA;Password=masterkey </property> <property name="show_sql">false</property> <property name="dialect">NHibernate.Dialect.FirebirdDialect</property> <property name="use_outer_join">true</property> <property name="command_timeout">444</property> <property name="query.substitutions">true 1, false 0, yes 1, no 0</property> </session-factory> </hibernate-configuration>

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

PostgreSQL

PostgreSQLversion 7.4 with latestNpgsqlworks almost perfectly. Later versions should work too.

Configuration example:

DB2 UDB

DB2 UDB is supported and reportedly even passes all the tests (see?t=73). Example configuration using the ODBC drivers that come with the ‘stinger’ release of db2:

MySQL那段岁月,无论从何种角度读你,你都完美无缺,

Nhibernate连接各种数据库(转:http://yuguo138.blog.163.com/bl

相关文章:

你感兴趣的文章:

标签云: