Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

21 ms

Page Size

25

Current Page

205 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 205 Results Showing 5101 - 5125 of 24441

ID Name Category Price Stock Rating Reviews SKU
5660 Bulk Product e2afebf3 Clothing $49.73 480 0.8 44 BULK-33dc4610
5661 Bulk Product 25054434 Toys & Games $847.54 433 0.4 0 BULK-f21a0bda
5662 Bulk Product 06d410a8 Electronics $334.97 170 2.5 7 BULK-07988b2c
5663 Bulk Product 71a040c1 Electronics $878.64 356 0.4 52 BULK-faabd08c
5664 Bulk Product 2516cf86 Electronics $165.56 352 2.6 48 BULK-85655908
5665 Bulk Product 19b998be Clothing $134.14 343 1.1 60 BULK-5f9ae701
5666 Bulk Product 3d62a827 Home & Garden $410.31 131 2.3 37 BULK-7cdc72c5
5667 Bulk Product e312410c Books $212.04 5 3.9 37 BULK-5915bf22
5668 Bulk Product c10ed655 Books $591.67 327 4.0 23 BULK-8e7a6ce1
5669 Bulk Product 5295a6ab Electronics $615.49 319 1.5 70 BULK-f5d29796
5670 Bulk Product a56f2f42 Toys & Games $358.99 20 0.6 10 BULK-e3844f73
5671 Bulk Product 72905ade Books $157.94 251 3.9 72 BULK-26011ce1
5672 Bulk Product 15f0dba5 Home & Garden $939.57 378 3.4 96 BULK-4d285077
5673 Bulk Product 08fad974 Electronics $85.68 342 0.6 39 BULK-6cc91ae0
5674 Bulk Product a563b5c4 Sports & Outdoors $204.84 68 3.6 4 BULK-16bfa6bf
5675 Bulk Product 42134091 Toys & Games $403.16 419 2.9 83 BULK-2cb72835
5676 Bulk Product 0e59b7bf Books $709.52 296 2.3 79 BULK-40382072
5677 Bulk Product cee6cd66 Books $444.39 234 4.0 98 BULK-ab593298
5678 Bulk Product 7c1b02b3 Clothing $181.53 69 1.2 45 BULK-0809a089
5679 Bulk Product f830cd99 Electronics $391.94 413 2.6 38 BULK-01bb990a
5680 Bulk Product 6beee3ce Electronics $398.60 482 2.9 52 BULK-8eb31d01
5681 Bulk Product 38976bdf Toys & Games $754.19 101 4.3 6 BULK-589967bb
5682 Bulk Product 7059346f Electronics $914.00 91 1.6 78 BULK-ef9cf23e
5683 Bulk Product 76ec9339 Sports & Outdoors $644.34 266 4.6 92 BULK-e30cd29f
5684 Bulk Product 2587bb19 Home & Garden $226.63 422 3.8 78 BULK-264289ac
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