Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

32 ms

Page Size

25

Current Page

582 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 582 Results Showing 14526 - 14550 of 24441

ID Name Category Price Stock Rating Reviews SKU
15085 Bulk Product 33f8764c Clothing $131.31 409 4.2 92 BULK-54bb91e3
15086 Bulk Product ff32adf8 Sports & Outdoors $361.87 132 4.1 91 BULK-9a6de182
15087 Bulk Product 00c9a190 Clothing $306.47 155 0.4 99 BULK-d195c31c
15088 Bulk Product f2453f33 Home & Garden $436.40 256 2.4 99 BULK-331dc32a
15089 Bulk Product bb0f5172 Sports & Outdoors $772.20 376 2.3 82 BULK-557928cb
15090 Bulk Product 65181e81 Home & Garden $585.76 210 4.3 65 BULK-1fc0f75c
15091 Bulk Product f811cdb2 Electronics $888.11 65 4.2 20 BULK-01143957
15092 Bulk Product 46170700 Home & Garden $261.21 41 2.4 53 BULK-01245580
15093 Bulk Product 1bdcd0ab Toys & Games $920.04 19 4.6 64 BULK-b7f4e875
15094 Bulk Product bdf22ea8 Home & Garden $289.82 32 0.3 96 BULK-0a1d9bca
15095 Bulk Product adcc7114 Electronics $492.56 41 1.6 14 BULK-55c57978
15096 Bulk Product 23d387cf Clothing $239.38 486 5.0 65 BULK-52ffb1eb
15097 Bulk Product 9b596615 Clothing $863.02 361 3.4 31 BULK-794dd9d3
15098 Bulk Product b88d5e00 Home & Garden $515.28 41 3.7 52 BULK-374dd245
15099 Bulk Product 528073e4 Books $202.24 193 1.2 26 BULK-e7947ce3
15100 Bulk Product 5193b13a Electronics $814.16 124 1.7 54 BULK-c30262a1
15101 Bulk Product 9b01cab9 Clothing $467.07 425 3.7 40 BULK-a664f9c7
15102 Bulk Product be7ca977 Home & Garden $727.83 277 2.9 17 BULK-9b498588
15103 Bulk Product def5a15f Books $627.22 310 0.1 12 BULK-27dceed3
15104 Bulk Product 3941bfce Clothing $586.91 416 2.0 8 BULK-9aca2595
15105 Bulk Product b9781a80 Sports & Outdoors $867.87 354 1.2 8 BULK-bac44b84
15106 Bulk Product b0ea3267 Sports & Outdoors $330.48 99 0.2 54 BULK-77cee513
15107 Bulk Product 8de009b4 Home & Garden $617.33 280 3.4 90 BULK-14ae469c
15108 Bulk Product a7626c9a Toys & Games $34.50 94 1.4 57 BULK-1d86d417
15109 Bulk Product 5e64d196 Home & Garden $140.58 397 3.0 3 BULK-1e604604
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