Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

50 ms

Page Size

25

Current Page

772 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 772 Results Showing 19276 - 19300 of 24441

ID Name Category Price Stock Rating Reviews SKU
19835 Bulk Product d710c864 Home & Garden $128.66 155 3.8 10 BULK-7ec930e8
19836 Bulk Product 72b439f0 Books $1,008.42 420 4.3 18 BULK-2563b051
19837 Bulk Product 18de59d3 Clothing $572.82 244 4.1 27 BULK-9a1bfbdc
19838 Bulk Product 40e54ac7 Clothing $142.23 489 1.3 29 BULK-b71799f8
19839 Bulk Product 1d733388 Electronics $797.66 276 3.2 49 BULK-efc86b7a
19840 Bulk Product 6f2c5e68 Books $322.68 41 4.1 11 BULK-1895152d
19841 Bulk Product c7c577f0 Sports & Outdoors $629.22 330 3.3 90 BULK-b66bf248
19842 Bulk Product e695921a Home & Garden $75.28 275 2.3 99 BULK-442fbb1e
19843 Bulk Product 9b359da6 Clothing $152.64 395 4.2 30 BULK-1abb9e1c
19844 Bulk Product 172790fc Books $177.09 323 1.4 85 BULK-f6c81322
19845 Bulk Product e493f363 Toys & Games $793.00 1 4.5 87 BULK-0410c1a1
19846 Bulk Product 2c1941c0 Books $955.88 350 0.5 35 BULK-7c67f391
19847 Bulk Product 03f75c56 Home & Garden $442.23 23 2.0 90 BULK-288d39e1
19848 Bulk Product 57551a85 Toys & Games $52.89 294 1.6 41 BULK-c35ca783
19849 Bulk Product 11bb813c Electronics $803.51 179 4.7 80 BULK-cb533f90
19850 Bulk Product bd0467f6 Electronics $447.68 104 4.6 1 BULK-d1b9597b
19851 Bulk Product b16a3903 Books $912.34 322 2.8 2 BULK-85fe1708
19852 Bulk Product 627fb990 Toys & Games $195.12 147 1.4 15 BULK-2e186f05
19853 Bulk Product c72c1430 Books $788.53 319 0.5 92 BULK-78d2d5bc
19854 Bulk Product 592d8fa6 Home & Garden $195.93 72 4.6 94 BULK-783234ff
19855 Bulk Product e1b55e1e Clothing $578.95 176 3.7 54 BULK-32a53ed3
19856 Bulk Product b8118554 Home & Garden $899.85 344 3.5 94 BULK-9c22058e
19857 Bulk Product 616a008d Clothing $60.26 54 3.2 75 BULK-d4676815
19858 Bulk Product 3bfa6aad Toys & Games $658.40 427 2.5 93 BULK-16babcbd
19859 Bulk Product 3c4d2b2c Toys & Games $614.86 306 1.8 71 BULK-e35937bb
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