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.
string cachedsearchname = "MyCachedVar";
var output = HttpContext.Cache[cachedsearchname];
if (output == null)
output = (from l in db.vwMyView select l)
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:
output = (from m in output2 where m.myrequestedoption
Challenge is I don't want to convert
ToList() yet as the cached result is quite large.
Any input much appreciated.