I am trying to make a final decision from Phil Haack here and sort using my LINQ query query, but instead of using a data context like him, I want to query IEnumerable (Of T) ... no luck.
Public Function DynamicGridData(ByVal sidx As String, ByVal sord As String, ByVal page As Integer, ByVal rows As Integer) As ActionResult
Dim list As List(Of User) = UserService.GetUserCollection()
Dim FilteredAndSortedList = list.OrderBy(sidx + " " + sord).Skip(pageIndex * pageSize).Take(pageSize)
Return JSON(jsonData)
End Function
I am currently getting an error below my line .OrderBy (sidx + "" + sord)
"Data type of type (s) of type in the extension method 'Public Function OrderBy (Of TKey) (keySelector As System.Func (Of User, TKey)) As System.Linq.IOrderedEnumerable (Of User)' defined in 'System.Linq .Enumerable 'cannot be inferred from these arguments. Specifying data types can explicitly fix this error. "
EDIT:
I found that the problem is that my “list” in the above example is not of type IQueryable. Just adding .AsQueryable () did the trick!
Public Function DynamicGridData(ByVal sidx As String, ByVal sord As String, ByVal page As Integer, ByVal rows As Integer) As ActionResult
Dim list As List(Of User) = UserService.GetUserCollection()
Dim FilteredAndSortedList = list.AsQueryable().OrderBy(sidx + " " + sord).Skip(pageIndex * pageSize).Take(pageSize)
Return JSON(jsonData)
End Function
source
share