Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

9 ms

Page Size

25

Current Page

221 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 221 Results Showing 5501 - 5525 of 24441

ID Name Category Price Stock Rating Reviews SKU
6060 Bulk Product fa18a911 Books $676.03 467 1.6 13 BULK-34e38f83
6061 Bulk Product 1e613757 Toys & Games $393.54 356 2.1 26 BULK-e12968a2
6062 Bulk Product 16a09d44 Books $935.10 22 4.1 84 BULK-a7416318
6063 Bulk Product dbbd8891 Clothing $519.52 433 1.0 65 BULK-2232c5e9
6064 Bulk Product 9d4b25a0 Clothing $880.55 284 1.8 43 BULK-699128d9
6065 Bulk Product 0630f3c6 Sports & Outdoors $34.36 389 2.7 84 BULK-f0b17f60
6066 Bulk Product b10fba29 Toys & Games $272.09 269 2.4 89 BULK-a273cc5c
6067 Bulk Product 06ff43c5 Books $203.49 116 3.5 97 BULK-687e4291
6068 Bulk Product 0fdfa734 Clothing $452.91 311 2.3 98 BULK-8265330a
6069 Bulk Product 990938fc Home & Garden $730.56 148 1.1 76 BULK-a4dab07c
6070 Bulk Product ceb1e0ba Books $10.76 452 3.4 35 BULK-6310b407
6071 Bulk Product 42569794 Electronics $500.75 453 0.8 90 BULK-9f381d07
6072 Bulk Product a17e4139 Books $325.59 402 0.4 28 BULK-f80eee20
6073 Bulk Product 7dc305f0 Sports & Outdoors $440.65 267 2.6 29 BULK-7d1013f8
6074 Bulk Product 792e0dfe Home & Garden $949.72 318 3.5 8 BULK-2fddb471
6075 Bulk Product b5ba9719 Electronics $230.39 1 3.8 25 BULK-4e8af2ba
6076 Bulk Product 4a04247a Toys & Games $142.34 328 0.2 57 BULK-2df895f4
6077 Bulk Product a8c7f2bc Clothing $255.67 138 2.8 7 BULK-435a736a
6078 Bulk Product fe0bcccf Sports & Outdoors $981.73 88 1.9 19 BULK-fa98dcde
6079 Bulk Product f99c7d68 Electronics $772.79 368 1.7 5 BULK-84e69ad2
6080 Bulk Product 5994a25a Books $198.86 295 0.8 32 BULK-37c2c653
6081 Bulk Product d486511d Clothing $121.59 96 2.9 30 BULK-dd4e4bcb
6082 Bulk Product aeb4976b Clothing $814.88 7 3.5 98 BULK-dc79296c
6083 Bulk Product cc2a0adb Books $723.63 422 1.5 12 BULK-98636f82
6084 Bulk Product 3b3d5f82 Toys & Games $34.97 366 2.3 61 BULK-eac79c6b
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