本文介绍了是否有可能使用(流利)nhibernate odbc连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



所有我需要传递的连接字符串是DSN。



我如何用(流利)nhibernate做到这一点? FluentNHibernate.Cfg.Db只提供一个带有DSN方法的OdbcConnectionStringBuilder类。我如何使用这个?您可以创建自己的 OdbcConfiguration 类,它派生自 PersistenceConfiguration



根据您的数据库,您将不得不在下面的类中替换Dialect。 b
$ b

  public class OdbcConfiguration:
PersistenceConfiguration< OdbcConfiguration,
FluentNHibernate.Cfg.Db.OdbcConnectionStringBuilder>
{
protected OdbcConfiguration()
{
驱动程序< NHibernate.Driver.OdbcDriver>();

$ b $ public static OdbcConfiguration MyDialect //< - 在这里插入任何名字
{
get
{
//插入方言你想用
返回新的OdbcConfiguration()方言< NHibernate.Dialect.MyDialect>();





然后,在Fluent NHibernate中,使用 OdbcConfiguration

  //替换MyDialect,
流利.Configure()
.Database(OdbcConfiguration.MyDialect.ConnectionString(DSN = ...; UID = ...; PWD = ...)
.Driver< NHibernate.Driver .OdbcDriver>()
.Dialect< NHibernate.Dialect.MyDialect>()//< - 再次改变这个
.etc ...


i have to use a custom odbc driver.

All i need to pass as a connection string is the DSN.

How do i do this with (fluent)nhibernate? FluentNHibernate.Cfg.Db does only offer a OdbcConnectionStringBuilder class with an DSN method. How do i use this?

解决方案

You can create your own OdbcConfiguration class that derives from PersistenceConfiguration.

Depending on your database, you will have to replace the Dialect in the following class.

public class OdbcConfiguration :
    PersistenceConfiguration<OdbcConfiguration,
        FluentNHibernate.Cfg.Db.OdbcConnectionStringBuilder>
{
    protected OdbcConfiguration()
    {
        Driver<NHibernate.Driver.OdbcDriver>();
    }

    public static OdbcConfiguration MyDialect // <-- insert any name here
    {
        get
        {
            // insert the dialect you want to use
            return new OdbcConfiguration().Dialect<NHibernate.Dialect.MyDialect>();
        }
    }
}

Then, in Fluent NHibernate, use that OdbcConfiguration:

// replace MyDialect here, too
Fluently.Configure()
    .Database(OdbcConfiguration.MyDialect.ConnectionString("DSN=...;UID=...;PWD=...")
            .Driver<NHibernate.Driver.OdbcDriver>()
            .Dialect<NHibernate.Dialect.MyDialect>() // <-- again, change this
            .etc...

这篇关于是否有可能使用(流利)nhibernate odbc连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 07:39