Most will recommend caching as a list. I know that is a solution and may be the one I go with. But, what if one wants to be able to treat a cached linq-to-sql with full IQueryable (IEnumerable?) functionality?
If one does try to cache the raw result, an error “Query results cannot be enumerated more then once”.
So, to make clear my questions are:
- Is the hashcode for Lists, IQueryable, and IEnumerable unique?
- If I want to cache the linq-to-sql result safely AND provide for maximum functionality afterward, how can I do that?
Once you have cached an IEnumerable, it is a “hydrated” list that is still queryable itself. The
AsQueryable()method can be used to query against the subset of records that are populated into the list:Here is some more good information on using AsQueryable():
http://weblogs.asp.net/zeeshanhirani/archive/2008/07/31/using-asqueryable-with-linq-to-objects-and-linq-to-sql.aspx