I have a fairly complex query (that includes a table valued function to allow full text searching) that I am trying to cache (HttpRuntime.Cache) for paging purposes. When I try to use the cached L2S query, I get the error stated above: The query results cannot be enumerated more than once.
I have tried assigning my query to another IQueryable object by calling AsIQueryable() on the cached object, but that does not help.
A开发者_如何学运维ny ideas?
You could store the results of the query in the cache instead of the query itself by calling .ToArray()
or .ToList()
extension methods which will execute the query immediately. Then you can enumerate the results from the cache as much as you wish.
use
var retVal = (.....).First() or ToList();
and use retVal.Name, retVal.Surname ....
if you use ToList();, you need to give an index like retVal[1].Name
精彩评论