tags:

views:

17

answers:

2

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.

Any ideas?

+3  A: 

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.

Darin Dimitrov
Thanks Darin - seems pretty obvious, but in the midst of other L2S issues, and using unfamiliar technology to begin with (asp.net mvc) I missed it.
jlnorsworthy
A: 

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

Serkan Hekimoglu