Я пытаюсь сохранить представление SQL в кэше, хотя я получаю ошибки независимо от того, что я пытаюсь ...
Когда я запускаю приведенный ниже код, в команде take появляются ошибки.
Unable to cast object of type '<TakeIterator>d__3a`1[View_UserSearch]' to type 'System.Linq.IOrderedEnumerable`1[View_UserSearch]'.
Вот код:
Using ctx As New NdpDataClassesDataContext
If System.Web.HttpRuntime.Cache("View_UserSearch") Is Nothing Then
Dim query = From vw In ctx.View_UserSearches
System.Web.HttpRuntime.Cache.Add("View_UserSearch", query.ToArray, Nothing, DateAdd(DateInterval.Hour, 1, Date.Now), Cache.NoSlidingExpiration, CacheItemPriority.AboveNormal, Nothing)
End If
Dim cacheQuery = DirectCast(System.Web.HttpRuntime.Cache("View_UserSearch"), View_UserSearch()).Where(Function(a) a.LoweredEmail.Contains(e.Text)).OrderByDescending(Function(a) a.UserID)
' Getting the total number of items that start with the typed text
e.ItemsCount = cacheQuery.Count
cacheQuery = cacheQuery.Skip(e.ItemsOffset).Take(10)
ComboBox2.DataSource = cacheQuery
ComboBox2.DataBind()
' Calculating the number of items loaded so far in the ListBox
e.ItemsLoadedCount = e.ItemsOffset + cacheQuery.Count
End Using
РЕДАКТИРОВАТЬ - РЕШЕНИЕ:
Мне удалось это исправить, изменив эту строку:
Dim cacheQuery = DirectCast(System.Web.HttpRuntime.Cache("View_UserSearch"), View_UserSearch()).Where(Function(a) a.LoweredEmail.Contains(e.Text)).OrderByDescending(Function(a) a.UserID)
до:
Dim cacheQuery = DirectCast(System.Web.HttpRuntime.Cache("View_UserSearch"), View_UserSearch()).Where(Function(a) a.LoweredEmail.Contains(e.Text))
cacheQuery = cacheQuery.OrderByDescending(Function(a) a.UserID)
Это изменяет переменную cacheQuery с IOrderedEnumerable на IEnumerable.