ate设置自定义DriverConnectionProvider

ate设置自定义DriverConnectionProvider

本文介绍了如何使用Fluent NHibernate设置自定义DriverConnectionProvider的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用Fluent NHibernate设置自定义DriverDriveProvider?

How to set custom DriverConnectionProvider with Fluent NHibernate?

最诚挚的问候,阿列克谢·扎哈罗夫(Alexey Zakharov)

Best regards,Alexey Zakharov

推荐答案

我找到了解决方案.这是小样本,该怎么做.

I find solution. Here is the small sample, which how it could be done.

Fluently.Configure()
    .Database(MsSqlConfiguration.MsSql2008
                    .ConnectionString(".......")
                    .ShowSql()
                    .Provider<TenantConnectionProvider>()
                    )

public class TenantConnectionProvider : DriverConnectionProvider
{
    public override IDbConnection GetConnection()
    {
        IDbConnection conn = Driver.CreateConnection();
        try
        {
            conn.ConnectionString = // Tenant connection string provider called here
            conn.Open();
        }
        catch (Exception)
        {
            conn.Dispose();
            throw;
        }

        return conn;


   }
}

这篇关于如何使用Fluent NHibernate设置自定义DriverConnectionProvider的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 01:50