Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

47 ms

Page Size

25

Current Page

654 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 654 Results Showing 16326 - 16350 of 24441

ID Name Category Price Stock Rating Reviews SKU
16885 Bulk Product c5d68138 Clothing $437.85 182 4.2 18 BULK-d5a53dff
16886 Bulk Product 6d210464 Home & Garden $675.61 244 2.1 88 BULK-40d3c148
16887 Bulk Product e5e066a9 Home & Garden $127.10 232 2.2 74 BULK-0a9c6f67
16888 Bulk Product 830a6a66 Clothing $177.32 449 0.2 89 BULK-7da8f9c2
16889 Bulk Product ea80e837 Clothing $965.99 404 4.8 42 BULK-a350278e
16890 Bulk Product c70bd9cc Electronics $712.32 251 3.9 54 BULK-46423dc2
16891 Bulk Product f7ac709b Home & Garden $137.41 36 4.7 52 BULK-b590a5d4
16892 Bulk Product ba3eca00 Clothing $221.47 204 2.4 42 BULK-7feadaff
16893 Bulk Product 29f4bd7c Sports & Outdoors $102.56 66 2.8 8 BULK-75e85c47
16894 Bulk Product 3412960c Books $612.19 183 2.9 35 BULK-247b89dc
16895 Bulk Product acc2026f Toys & Games $956.40 71 2.6 18 BULK-4586b9a5
16896 Bulk Product 79b4e713 Electronics $980.83 486 4.4 10 BULK-4936770b
16897 Bulk Product 5266f7c7 Home & Garden $785.82 156 4.9 27 BULK-af0ebf31
16898 Bulk Product 714f39fe Clothing $208.18 483 2.5 81 BULK-7b3b8e26
16899 Bulk Product 4d36f064 Clothing $83.10 250 1.0 89 BULK-bec2dc3f
16900 Bulk Product 886608b1 Home & Garden $894.19 149 2.8 37 BULK-5e63eefa
16901 Bulk Product e97ecc6a Toys & Games $280.54 370 1.3 44 BULK-cdd55d9a
16902 Bulk Product 5ca38278 Toys & Games $824.67 37 0.9 98 BULK-888036c1
16903 Bulk Product bd2f2998 Clothing $970.97 219 2.9 0 BULK-32d41199
16904 Bulk Product 2c33d551 Sports & Outdoors $871.56 337 2.3 16 BULK-c7242464
16905 Bulk Product 14c944aa Home & Garden $441.91 38 2.0 3 BULK-51ef8a6b
16906 Bulk Product 5ec8089d Books $242.98 390 1.8 34 BULK-dddcbaf2
16907 Bulk Product b781e25f Books $933.74 295 4.9 41 BULK-b6afb7ac
16908 Bulk Product 1ee8cbdb Books $784.27 388 2.4 9 BULK-fdf54c6c
16909 Bulk Product 9f4738b7 Clothing $839.19 419 3.3 56 BULK-87627d46
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