Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

14 ms

Page Size

25

Current Page

237 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 237 Results Showing 5901 - 5925 of 24441

ID Name Category Price Stock Rating Reviews SKU
6460 Bulk Product 549d0bfd Clothing $309.94 157 3.0 0 BULK-a0daa0c1
6461 Bulk Product 3d92c007 Books $492.26 34 0.6 66 BULK-d7c7c7b9
6462 Bulk Product c38554db Clothing $649.43 47 0.5 72 BULK-b8686f51
6463 Bulk Product 2843df10 Toys & Games $70.42 271 4.2 76 BULK-09fb6807
6464 Bulk Product 76b1f54d Clothing $947.43 107 3.9 74 BULK-718c3406
6465 Bulk Product ec6e7340 Clothing $376.89 232 0.5 69 BULK-0bb55819
6466 Bulk Product ab05476e Books $335.12 63 4.0 75 BULK-dcf48ebb
6467 Bulk Product 41e322e1 Toys & Games $462.61 200 4.5 98 BULK-706d630b
6468 Bulk Product 0350fdb2 Books $244.14 437 1.9 28 BULK-cf52dda7
6469 Bulk Product f9ff7adb Electronics $644.94 143 4.0 61 BULK-9ee13bcd
6470 Bulk Product 60a70e9d Electronics $274.61 355 1.0 74 BULK-13a8d97f
6471 Bulk Product 7bf80720 Sports & Outdoors $757.55 163 4.0 14 BULK-549a170b
6472 Bulk Product a501ed31 Books $263.06 322 0.4 36 BULK-b2d44f10
6473 Bulk Product 4fca7a37 Books $557.95 0 0.1 38 BULK-ace5c397
6474 Bulk Product 4a789c6f Books $430.17 298 1.9 12 BULK-62cb184a
6475 Bulk Product 5c84f960 Books $90.21 384 4.4 28 BULK-6f47c1db
6476 Bulk Product 53d6db40 Clothing $533.70 327 2.9 93 BULK-5a2db449
6477 Bulk Product 0ad2d454 Books $570.00 449 0.8 62 BULK-803ae568
6478 Bulk Product b8a69e9a Books $788.21 132 2.4 77 BULK-1f52cfc9
6479 Bulk Product 1d9e5588 Toys & Games $595.06 371 1.8 80 BULK-ccb07b25
6480 Bulk Product 64c5e219 Electronics $114.69 323 4.3 59 BULK-d3048f12
6481 Bulk Product daf9d092 Toys & Games $541.39 266 4.7 74 BULK-054bf080
6482 Bulk Product 0b7db3d5 Toys & Games $540.86 331 4.4 14 BULK-5620e484
6483 Bulk Product ba56a727 Clothing $164.19 43 4.6 27 BULK-abdc4b15
6484 Bulk Product 445c30b0 Books $950.18 59 4.8 6 BULK-96863415
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