In Application_Start i cache some object which i got through LINQ to SQL.
objDataContext objBetting = new objDataContext();
var testObjects= from element in objBetting.Elements
select new { element.attribute };
HttpRuntime.Cache["test"] = testObjects;
On some page i want to read value testObject.attribute. I could only:
var objS = (IQueryable)Cache["test"];
I cache anonymous type of object, how to get properties, maybe it is better question.
OK, i will make and populate object of System.Data.Linq.Table type, and i will cache it, to able casting.
Don’t cache a queryable. They’re lazily evaluated, and the chances are high that (1) the context won’t be there when you read the cache, so enumerating it will die, and (2) it isn’t serializable, so it won’t work with distributed caches.
If you have to cache a list of something, put it into an array of primitive types.