SqlCacheDependecy命令通知不起作用

时间:2008-10-27 20:36:54

标签: sql-server linq-to-sql caching

我一直试图让sqlcachedependecy工作,但它似乎无法正常工作

我在我的web.config和global.asa中得到了正确的设置,但是当我运行此查询并且从网站内部或外部对数据库进行更改时,缓存的对象不会更新请有人救命?我知道它不是因为这个查询正在查询视图,因为我使用直接的SqlDependecy进行了测试,并且通知正常。

  public IQueryable<VictoryList> GetVictoryList()
   {
                string cacheKey = HttpContext.Current.User.Identity.Name + "victoryCacheKey";
                IQueryable<VictoryList> cachednews = (IQueryable<VictoryList>)HttpContext.Current.Cache.Get(cacheKey);

                if (cachednews == null)
                {

                    var results = from v in _datacontext.ViewVictoryLists
                                  orderby _datacontext.GetNewId()
                                  select new VictoryList
                                  {
                                      MemberID = v.MemberID,
                                      Username = v.Aspnetusername,
                                      Location = v.Location,
                                      DaimokuGoal = v.DaimokuGoal,
                                      PreviewImageID = v.PreviewImageID,
                                      TotalDaimoku = v.TotalDaimoku,
                                      TotalDeterminations = v.TotalDeterminations,
                                      DeterminationID = v.DeterminationID,
                                      DeterminationName = v.DeterminationName
                                  };
                    results = results.ToList().AsQueryable();
                    SqlCacheDependencyAdmin.EnableNotifications(_datacontext.Connection.ConnectionString);
                    SqlCacheDependency dependency =
                     new SqlCacheDependency(_datacontext.GetCommand(results) as SqlCommand);



                    HttpContext.Current.Cache.Insert(cacheKey, results, dependency);

                    return results;
                }
                return cachednews;
   }

1 个答案:

答案 0 :(得分:2)

根据创建通知查询的规定限制,列于msdn ...

声明不得引用视图。