Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

13 ms

Page Size

25

Current Page

400 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 400 Results Showing 9976 - 10000 of 24441

ID Name Category Price Stock Rating Reviews SKU
10535 Bulk Product 43a32ec5 Home & Garden $755.89 49 1.6 83 BULK-bdc98050
10536 Bulk Product 4c0ed2ea Books $812.77 93 2.9 86 BULK-30575a1b
10537 Bulk Product b186cedf Electronics $212.32 102 0.7 0 BULK-a9d621e1
10538 Bulk Product b9e8f393 Books $351.65 3 3.1 76 BULK-b640c368
10539 Bulk Product 0c7e4d48 Clothing $947.00 447 1.3 32 BULK-5472518d
10540 Bulk Product 19986bf4 Clothing $33.59 368 2.5 24 BULK-3ef88a15
10541 Bulk Product acd4239b Toys & Games $302.35 141 3.1 98 BULK-ca81a78c
10542 Bulk Product 552cff6b Electronics $871.96 243 4.7 32 BULK-1025d133
10543 Bulk Product 2e7678e6 Clothing $646.73 412 2.0 89 BULK-a5f2778a
10544 Bulk Product bbf0ce58 Electronics $383.60 172 4.5 38 BULK-1559f40f
10545 Bulk Product ebb56482 Books $221.61 394 4.6 3 BULK-5ab2c503
10546 Bulk Product dbd1ecee Home & Garden $156.87 407 4.4 72 BULK-c2853ee4
10547 Bulk Product b8d7dc98 Books $58.87 485 2.6 72 BULK-421f0245
10548 Bulk Product 55849927 Clothing $269.22 236 4.2 58 BULK-529fff32
10549 Bulk Product 38364dc4 Toys & Games $440.44 485 2.2 67 BULK-8d028ba1
10550 Bulk Product 19366457 Books $847.00 185 3.8 69 BULK-7192baa9
10551 Bulk Product 6b1e2a66 Toys & Games $898.88 56 2.1 8 BULK-77c5bb9c
10552 Bulk Product 68954f27 Home & Garden $570.30 251 0.8 95 BULK-bef4288b
10553 Bulk Product b43f9e1b Home & Garden $333.03 381 0.2 26 BULK-41659ff6
10554 Bulk Product c48cdb9b Clothing $920.58 98 1.2 1 BULK-ffcffeec
10555 Bulk Product 849a2016 Toys & Games $251.16 369 1.1 18 BULK-1784fb6d
10556 Bulk Product a3e80170 Home & Garden $911.34 229 0.1 0 BULK-43c79f97
10557 Bulk Product a7c15f13 Sports & Outdoors $151.59 479 0.2 8 BULK-3165d12f
10558 Bulk Product 0da12b06 Toys & Games $639.11 85 1.1 82 BULK-dc7cda01
10559 Bulk Product 797d23a6 Clothing $183.43 235 3.7 53 BULK-228e77df
Implementation Code
// Efficient pagination with Skip and Take
public async Task<PaginatedResult<DemoProduct>> GetPaginatedProductsAsync(int page, int pageSize)
{
    // Get total count (cached if possible)
    var totalCount = await _context.DemoProducts.CountAsync(p => p.IsActive);
    
    // Get page of results
    var items = await _context.DemoProducts
        .Where(p => p.IsActive)
        .OrderBy(p => p.Id) // Important: Must have ORDER BY for consistent paging
        .Skip((page - 1) * pageSize) // OFFSET in SQL
        .Take(pageSize) // FETCH NEXT in SQL
        .AsNoTracking() // No tracking needed for read-only
        .ToListAsync();

    return new PaginatedResult<DemoProduct>
    {
        Items = items,
        TotalCount = totalCount,
        Page = page,
        PageSize = pageSize
    };
}
Pagination Best Practices
  • Always use OrderBy: Skip/Take require stable sorting for consistent results
  • Use AsNoTracking(): Pagination queries are typically read-only
  • Consider caching: Cache total count if dataset changes infrequently
  • Limit max page size: Prevent users from requesting too many records at once
  • Use indexed columns: Ensure ORDER BY columns are indexed for performance