Hi Guys/Lady's , wondering can any one help me with the following problem/question.
Am trying to cache Iqueryable converted tolist<> & get data back out of the cache. However, can't work out why it is not working.
public class QDatalist
{
public int q_id { get; set; }
public string title { get; set; }
public int? marks { get; set; }
}
private void bindquestions()
{
IQueryable<QDatalist> data;
using (DataClassesDataContext db = new DataClassesDataContext())
{
if (Cache.Get("Qbank") == null)
{
data = db.tb_questions.Select(x => new QDatalist {marks = x.marks, q_id = x.q_id, title = x.title});
Cache.Insert("Qbank", data.ToList<QDatalist>(), null, System.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(120));
}
else
{
List<QDatalist> M = (List<QDatalist>)Cache.Get("Qbank");
data = M.AsQueryable<QDatalist>();
}
}
}
Error am getting when try Get("Qbank") is:
System.InvalidCastException: [A]System.Collections.Generic.List1[member_Default+QDatalist] cannot be cast to [B]System.Collections.Generic.List
1[member_Default+QDatalist]. Type A originates from 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' in the context 'LoadNeither' at location 'C:\Windows\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll'. Type B originates from 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' in the context 'LoadNeither' at location 'C:\Windows\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll'.
Can any one help? Thank you for your time, Chris