C# NHibernate多租户数据库二级缓存(应用结构)工作不正常
在我们的wcf服务中,我们使用多租户数据库。我们将根据用户切换数据库。我们使用nhibernate和appfabric进行二级缓存。当启用二级缓存时,它将返回不同租户数据库的缓存数据。当二级缓存关闭时,它将正常工作,是否有任何方法可以让它与带appfabric缓存的多租户数据库一起工作。我们使用的是nhibernate 3.0.0.4000 注意:我们不需要syscache,因为它是内存缓存 下面是customprovider,用于更改基于租户的连接字符串并在配置中更改提供程序C# NHibernate多租户数据库二级缓存(应用结构)工作不正常,c#,nhibernate,fluent-nhibernate,appfabric,second-level-cache,C#,Nhibernate,Fluent Nhibernate,Appfabric,Second Level Cache,在我们的wcf服务中,我们使用多租户数据库。我们将根据用户切换数据库。我们使用nhibernate和appfabric进行二级缓存。当启用二级缓存时,它将返回不同租户数据库的缓存数据。当二级缓存关闭时,它将正常工作,是否有任何方法可以让它与带appfabric缓存的多租户数据库一起工作。我们使用的是nhibernate 3.0.0.4000 注意:我们不需要syscache,因为它是内存缓存 下面是customprovider,用于更改基于租户的连接字符串并在配置中更改提供程序 public c
public class ContextAwareConnectionProvider : DriverConnectionProvider
{
/// <summary>
/// Gets Database Connection String
/// </summary>
protected override string ConnectionString
{
get
{
//If the TenantConnection string is null,set the master Azure SQL db which is used for the initial Tenant identification
string tenantConnectionString = Convert.ToString(ExtendedConstants.TENANTCONNECTIONSTRING);
if (string.IsNullOrEmpty(tenantConnectionString))
{
return base.ConnectionString;
}
return tenantConnectionString;
}
}
}
公共类ContextawarReconnectionProvider:DriverConnectionProvider
{
///
///获取数据库连接字符串
///
受保护的重写字符串连接字符串
{
得到
{
//如果租户连接字符串为空,请设置用于初始租户标识的主Azure SQL db
string-tenantConnectionString=Convert.ToString(ExtendedConstants.tenantConnectionString);
if(string.IsNullOrEmpty(租户连接字符串))
{
返回base.ConnectionString;
}
返回租户连接字符串;
}
}
}
MyNamespace.ContextawarReconnectionProvider,Myassembly
我能想到的一个选项是在数据库中拥有唯一的实体Id!