I am trying to use a cached variable for LINQ and I'm having issues accessing the cached variable in order to run further select LINQ statements.
Code:
string cachedsearchname = "MyCachedVar";
var output = HttpContext.Cache[cachedsearchname];
if (output == null)
{
output = (from l in db.vwMyView select l)
HttpContext.Cache.Insert(cachedsearchname, output);
}
var output2 = (List<vwMyView>)HttpContext.Cache[cachedsearchname];
The last line throws the error:
System.InvalidCastException: 'Unable to cast object of type 'System.Data.Entitiy.Infrastracture.DbQuery'1[vwMyView]' to type 'System.Collections.Generic.List'1[vwMyView]'
My goal would be to run:
if (PassedQuerystring.Contains("MyRequestedOption")
{
output = (from m in output2 where m.myrequestedoption
.Contains("MyRequestedOption")
select m)
}
Challenge is I don't want to convert ToList()
yet as the cached result is quite large.
Any input much appreciated.
从缓存中检索时,需要强制转换为与缓存中相同的数据类型。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.