Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

72 ms

Page Size

25

Current Page

197 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 197 Results Showing 4901 - 4925 of 24441

ID Name Category Price Stock Rating Reviews SKU
5460 Bulk Product 5b85f33b Sports & Outdoors $352.47 93 1.8 74 BULK-729a4df5
5461 Bulk Product f591ed97 Sports & Outdoors $101.55 467 4.4 92 BULK-6dde1dff
5462 Bulk Product bc98fa54 Sports & Outdoors $730.76 389 1.9 26 BULK-7bb9b37d
5463 Bulk Product 210f0206 Books $569.16 252 1.6 17 BULK-f48f7a95
5464 Bulk Product f078ee2f Books $718.78 490 3.8 48 BULK-e26e2571
5465 Bulk Product 6c27b007 Clothing $189.19 71 2.8 97 BULK-d976948d
5466 Bulk Product 314278b7 Clothing $941.64 370 2.4 80 BULK-55c04b4e
5467 Bulk Product 889e25fc Books $229.18 368 1.8 13 BULK-318329c9
5468 Bulk Product b8d27363 Home & Garden $785.72 116 1.1 33 BULK-89e408da
5469 Bulk Product 95cd4545 Toys & Games $424.96 50 3.7 5 BULK-715d4171
5470 Bulk Product e32493c1 Electronics $425.28 215 2.3 89 BULK-373897e0
5471 Bulk Product 88213660 Sports & Outdoors $318.99 156 3.7 44 BULK-709a0721
5472 Bulk Product 24d967fb Sports & Outdoors $95.92 362 3.9 82 BULK-0117bfb5
5473 Bulk Product f08db0f2 Toys & Games $802.77 390 2.1 96 BULK-5ead4f4e
5474 Bulk Product d55fabdc Books $363.66 223 4.3 40 BULK-1cf3aab6
5475 Bulk Product ad58c032 Sports & Outdoors $20.69 493 3.9 83 BULK-d7deffc5
5476 Bulk Product c70c3308 Sports & Outdoors $871.49 461 1.3 94 BULK-1073a122
5477 Bulk Product f58c2639 Clothing $880.89 384 3.1 0 BULK-903aaba6
5478 Bulk Product d9c8527b Books $728.14 344 1.2 99 BULK-c5f07030
5479 Bulk Product ec18441d Clothing $77.42 41 2.8 87 BULK-0f236254
5480 Bulk Product 619bdf13 Clothing $647.90 221 1.1 53 BULK-50725f19
5481 Bulk Product b7bb6e39 Sports & Outdoors $519.27 287 2.7 75 BULK-d2836d82
5482 Bulk Product 8e931c54 Clothing $946.03 98 2.1 57 BULK-aa0e6c73
5483 Bulk Product 847edcaa Books $463.43 74 4.1 47 BULK-8b1a8c8c
5484 Bulk Product f5754cd8 Home & Garden $858.26 370 3.0 16 BULK-d93053b9
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