如何使用Fluent NHibernate设置自定义DriverConnectionProvider?
此致,
阿列克谢·扎哈罗夫(Alexey Zakharov)
最佳答案
我找到解决办法。这是小样本,该怎么做。
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;
}
}