开发者

L2S, Caching, and error: The query results cannot be enumerated more than once

开发者 https://www.devze.com 2023-01-06 13:50 出处:网络
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 q

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号