Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

10 ms

Page Size

25

Current Page

332 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 332 Results Showing 8276 - 8300 of 24441

ID Name Category Price Stock Rating Reviews SKU
8835 Bulk Product ef56811d Sports & Outdoors $791.37 92 1.6 32 BULK-70223a03
8836 Bulk Product 944dabf1 Books $952.91 267 4.1 96 BULK-3ff3d2b2
8837 Bulk Product 3637f6ff Electronics $809.23 494 0.5 38 BULK-43d59097
8838 Bulk Product 2ce9c197 Clothing $455.46 162 2.0 61 BULK-e9c79f6a
8839 Bulk Product c8e46c9f Home & Garden $447.50 218 0.0 16 BULK-dec66c2e
8840 Bulk Product c538789f Books $664.49 62 3.7 72 BULK-e7a667a1
8841 Bulk Product d1993650 Clothing $996.27 319 4.4 31 BULK-e151bedb
8842 Bulk Product 6a9beb47 Electronics $489.19 175 3.6 83 BULK-f0acc6be
8843 Bulk Product f56a8ee7 Home & Garden $472.87 363 3.3 60 BULK-aef913bc
8844 Bulk Product e5576c59 Clothing $853.84 480 3.3 35 BULK-d409ae0b
8845 Bulk Product 1e2f1414 Home & Garden $421.45 112 3.2 51 BULK-6d1766b9
8846 Bulk Product 42e17a9e Sports & Outdoors $485.19 141 2.1 71 BULK-8037666d
8847 Bulk Product ae60c4a6 Sports & Outdoors $263.31 330 3.2 50 BULK-ce62e83d
8848 Bulk Product 890d9a39 Toys & Games $885.51 1 2.7 89 BULK-09be8d46
8849 Bulk Product 39035d5b Books $243.39 467 2.3 36 BULK-f57654fd
8850 Bulk Product ce6750e7 Home & Garden $403.38 242 1.2 46 BULK-0f94ba24
8851 Bulk Product 2eaa49b6 Toys & Games $443.69 433 5.0 57 BULK-2ba4ac85
8852 Bulk Product fa84977d Electronics $791.65 268 1.7 75 BULK-a32c433e
8853 Bulk Product 8d88f405 Sports & Outdoors $338.40 33 2.6 45 BULK-d9624b3c
8854 Bulk Product 798eb8ca Clothing $355.60 371 2.6 39 BULK-4500553d
8855 Bulk Product b6a42e41 Clothing $696.28 161 1.2 25 BULK-3449d459
8856 Bulk Product b9338b6b Clothing $448.77 189 0.8 2 BULK-27a22201
8857 Bulk Product 97e98e6b Electronics $928.53 218 4.7 41 BULK-3aab73ec
8858 Bulk Product 65140462 Clothing $960.85 403 4.4 95 BULK-2b873ca1
8859 Bulk Product 4e828847 Books $22.33 49 0.7 10 BULK-f172ba9a
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