本文介绍了使用LINQ和SqlCacheDependency的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Visual Studio 2008,C#和SQL Server 2005.
I am using Visual Studio 2008, C# and SQL Server 2005.
在NET上看到了将LINQ与SqlCacheDependency相关联的示例。
have seen examples on the NET that associates LINQ with SqlCacheDependency.
例如 http://www.writebetterbits.com/2008/01/overview-of-sql-server-2005-database_11.html 结果
但是没有功能,缓存是创建的但是当更新表时缓存不是无效。
But not function, the cache is a created However when update table the cache is not invalidation.
我改变数据库:
I am Alter a DataBase:
代码片段
推荐答案
NewsDataContext DbNews = new NewsDataContext( |
DataBaseConnections.GetConnection(ENU mDatBase.NEWS.ToString())); |
var query = 来自 p在DbNews.KeyWords中选择p; |
SqlCommand cmd =(的SqlCommand)DbNews.GetCommand(查询); |
SqlCacheDependency 依赖 = new 的SqlCacheDependency(CMD); |
System.Web.HttpContext.Current.Cache.Add(cacheKey,ListKeyWord,dependency,DateTime.MaxValue,TimeSpan。零,CacheItemPriority.AboveNormal,NULL); |
ListKeyWord = 查询 。ToList(); |
NewsDataContext DbNews = new NewsDataContext( |
DataBaseConnections.GetConnection(enumDatBase.NEWS.ToString())); |
var query = from p in DbNews.KeyWords select p; |
SqlCommand cmd = (SqlCommand)DbNews.GetCommand(query); |
SqlCacheDependency dependency = new SqlCacheDependency(cmd); |
System.Web.HttpContext.Current.Cache.Add(cacheKey, ListKeyWord, dependency, DateTime.MaxValue,TimeSpan.Zero, CacheItemPriority.AboveNormal, null); |
ListKeyWord = query.ToList(); |
这篇关于使用LINQ和SqlCacheDependency的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!