LINQ and paging with DataTable - can't Skip work?

Okay, so that might be a dumb question, but I can't figure it out. I thought I would try LINQ against DataTable. I received my request and now I'm trying to implement a simple run.

DataTable dataTable = null; dataTable = GetAllDataTables(); var query = from r in dataTable.AsEnumerable() orderby r.Field<string>(Constants.fileName) select r; query.Skip(WPP_PAGE_SIZE * pageIndex).Take(WPP_PAGE_SIZE); 

My problem is that I get an error message in the .Skip (...) request.

Error 1 'System.Data.OrderedEnumerableRowCollection' does not contain a definition for 'Skip' and does not use the Skip extension method. Accepting the first argument of type 'System.Data.OrderedEnumerableRowCollection' (you don’t see the link using the directive or assembly?)

Links I have:

  • Microsoft.SharePoint
  • System
  • System.Core
  • System.Data li>
  • System.Data.DataSetExtensions
  • System.web
  • System.xml

What am I missing?

+4
source share
2 answers

You need using System.Linq; at the top of the file.

The second problem is that you need to assign the result of Skip and Take to something else, otherwise the result will simply be discarded:

 var query2 = query.Skip(WPP_PAGE_SIZE * pageIndex).Take(WPP_PAGE_SIZE); 
+7
source
 using System.Linq? 
+2
source

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


All Articles