此代码工作正常,只要在数据库中更改数据,它就会使数据无效:
AggregateCacheDependency aggDep = new AggregateCacheDependency();
System.Data.SqlClient.SqlCommand ocom = new System.Data.SqlClient.SqlCommand();
SqlCacheDependency SqlDep = new SqlCacheDependency("DBNAMEINCONFIG", "Products");
aggDep.Add(SqlDep);
虽然我不能对整个“产品”表直接无效,但我需要能够使表上的选择无效。我遇到的问题是以下代码在数据更改时不会使缓存无效:
AggregateCacheDependency aggDep = new AggregateCacheDependency();
System.Data.SqlClient.SqlCommand ocom = new System.Data.SqlClient.SqlCommand();
ocom.CommandText = "SELECT ID,ClinicID,Price,Enabled FROM dbo.Products WHERE ClinicID = 1";
ocom.Connection = new System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings["DBSTRING"].ToString());
SqlCacheDependency SqlDep = new SqlCacheDependency(ocom);
aggDep.Add(SqlDep);
我试图包含分析此问题所需的所有信息,但如果我应该包含更多信息,请告诉我!