如何使用Fluent NHibernate设置自定义DriverConnectionProvider?
祝你好运, Alexey Zakharov
答案 0 :(得分:13)
我找到解决方案。这是一个小样本,它是如何完成的。
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;
}
}