0

I have a selection of a huge set of data and I would like to use a paging and to select only k elements, starting from the o'th element in the set, to support my paging. I don't like the idea of loading the whole data set with linq and then get only a subset, using the GetRange method, because the amount of elements can be very huge. For instance, if I have 6 000 000 rows in a table and want to show them, using a paging size of 10 and we are looking at the 5'th page, I would like to generate an SQL Server query, using Linq, which will select only 10 elements of my large table of 6 000 000 rows, because this way my application will be more efficient.

Does anybody know about a support for paging in Linq?

Thank you in advance,

Lajos Árpád.

Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175

3 Answers3

1

Use Skip and Take.

collection.Skip(pageIndex * pageSize).Take(pageSize);
David
  • 1,143
  • 7
  • 9
0

You can use the Skip and Take methods

query = context.Table.Skip(number).Take(number);
Aducci
  • 26,101
  • 8
  • 63
  • 67
0

You can use Take and Skip.

var page = query.Skip(1000).Take(10);
Mark Byers
  • 811,555
  • 193
  • 1,581
  • 1,452