我發現這個問題How to cache data in a MVC application,我想知道能夠使用IQueryable數據的這種方法。ASP.NET MVC - 緩存IQueryable數據
Public Function GetUsers() As IQueryable(Of User) Implements IUserRepository.GetUsers
Dim users = (From u In dc.Users
Select u)
Return users.AsQueryable
End Function
我可以改變這
Public Function GetUsers() As IQueryable(Of User) Implements IUserRepository.GetUsers
Dim users = Cache("users")
If users Is Nothing Then
users = (From u In dc.Users
Select u)
Cache("users") = users
End If
Return users.AsQueryable
End Function
這將工作。但是你不應該緩存IQueryable,因爲它們持有DataContext。首先將數據轉換爲列表。例如users = dc.Users.ToList(); – Jacob 2010-08-09 22:57:07