2015-04-04 82 views
-1

我正在使用RedisCache,EntityFramework和SqlServerDB。 我想要缓存整个表数据,并且必须在我的视图中显示缓存表。 我正在使用下面的代码,但不工作。有人向我暗示。如何从实体框架中的Redis缓存中获取总表数据?

的ActionResult:

[HttpGet] 
    public ActionResult GetDataFromRedisCache(string cachetable) 
    { 
     IDatabase cache = Connection.GetDatabase(); 
     MytableControl getTblDatafromCache = GetTblDataFromRedis(cachetable); 
     return View(getTblDatafromCache); 
    } 

我的类别:

MytableControl GetTblDataFromRedis(string cachetable) 
    { 
     IDatabase cache = Connection.GetDatabase(); 
     Stopwatch sw = Stopwatch.StartNew(); 
     MytableControl m; 

     try 
     { 
      m = (MytableControl)cache.Get(cachetable.ToString()); //Get(id.ToString()); 
     } 

     catch (TimeoutException tx) 
     { 
      //Logger("getMovie fail, ID = " + id.ToString(), tx); 
      return GetTblDataFromRedis(cachetable); 
     } 

     if (m == null) 
     { 
      MytableControl RadiscacheTbl = from temp in obj.MytableControl select temp; ; 
      cache.Set(cachetable, RadiscacheTbl); 
      StopWatchMiss(sw); 
      return RadiscacheTbl; 
     } 
     StopWatchHit(sw); 

     return m; 
    } 

我能不能够获得数据。异常作为

类型 'System.Data.Entity.Infrastructure.DbQuery`1 [[WebECpoc.Tbl_Inbnd_EquipmentControl, WebECpoc,版本= 1.0.0.0,文化=中性公钥=空]]' 在 大会'EntityFramework,Version = 6.0.0.0,Culture = neutral, PublicKeyToken = b77a5c561934e089'未标记为可序列化。

注:连接每一件事神和秒表也工作正常

+0

你放入缓存的内容应该是可序列化的。 “RadiscacheTbl”似乎是一个尚未实现的查询。调用'ToList()',然后尝试将其保存到缓存中。 – Chandermani 2015-04-06 06:16:24

回答

相关问题