Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set custom DriverConnectionProvider with Fluent NHibernate

How to set custom DriverConnectionProvider with Fluent NHibernate?

Best regards, Alexey Zakharov

like image 878
Alexey Zakharov Avatar asked May 28 '10 09:05

Alexey Zakharov


1 Answers

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;


   }
}
like image 152
Alexey Zakharov Avatar answered Oct 27 '22 22:10

Alexey Zakharov