How to use the System.LINQ.Dynamic assembly with IEnumerable (Of T)

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
+3
source share
2 answers

I'm not sure, but I think this is due to the fact that you are going to the OrderBy line, not the Expression (TDelegate) that it expects.

Take a look at this article and see if it helps.

http://msdn.microsoft.com/en-us/library/bb549264.aspx

Edit:

Phil Code , . , . , , ? , , , . , JSON (jsondata), , jsondata. , , , orderby. , , , , , .

+2

Source: https://habr.com/ru/post/1708285/


All Articles