Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

29 ms

Page Size

25

Current Page

806 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 806 Results Showing 20126 - 20150 of 24441

ID Name Category Price Stock Rating Reviews SKU
20685 Bulk Product 0c6ca2de Home & Garden $587.75 384 0.6 95 BULK-3ffb9c7d
20686 Bulk Product af5e54d8 Books $435.21 219 4.9 83 BULK-9788ddf3
20687 Bulk Product da50629e Books $675.97 439 2.2 98 BULK-8000dffc
20688 Bulk Product 5170cf19 Home & Garden $287.67 78 1.0 20 BULK-56199900
20689 Bulk Product a0d5012c Clothing $211.18 409 0.3 35 BULK-45df0c13
20690 Bulk Product e71bead6 Toys & Games $61.78 463 1.1 21 BULK-77737c60
20691 Bulk Product 79bf24d3 Electronics $179.28 374 2.9 55 BULK-2a6080f5
20692 Bulk Product 7fabac99 Toys & Games $932.93 444 4.5 14 BULK-1559c4cf
20693 Bulk Product 05bbde4e Home & Garden $1,005.56 304 0.3 26 BULK-782a80bc
20694 Bulk Product d9b685e1 Sports & Outdoors $145.17 137 0.1 55 BULK-1a29e4bb
20695 Bulk Product c474eccc Electronics $686.19 332 1.3 15 BULK-3ad5e50d
20696 Bulk Product 1eb63e3a Sports & Outdoors $238.99 8 4.3 42 BULK-3b590aa3
20697 Bulk Product 1d5be77e Toys & Games $768.97 72 1.9 69 BULK-e0d2cb28
20698 Bulk Product 39a48623 Home & Garden $845.01 382 1.9 80 BULK-0960322d
20699 Bulk Product f2157154 Toys & Games $947.27 122 1.6 26 BULK-ff06f5f4
20700 Bulk Product 19ea6a02 Electronics $382.78 139 3.5 89 BULK-77cd29f7
20701 Bulk Product e0b5f0bf Electronics $820.99 291 4.8 95 BULK-95ace552
20702 Bulk Product 9f263f69 Toys & Games $384.77 336 0.4 62 BULK-e17ddaf3
20703 Bulk Product 54ff8db6 Clothing $287.38 443 4.7 3 BULK-e8ac1aed
20704 Bulk Product 9ed28637 Home & Garden $990.59 54 4.4 55 BULK-302c1d51
20705 Bulk Product 45298bec Home & Garden $420.21 153 3.7 86 BULK-9bbace06
20706 Bulk Product a2e70af4 Clothing $966.05 156 0.1 38 BULK-c28ad6c8
20707 Bulk Product 40eaf86b Toys & Games $69.18 162 0.7 8 BULK-65a76e6e
20708 Bulk Product 262a2fc7 Electronics $374.18 358 3.9 28 BULK-c3260a0b
20709 Bulk Product 497bfeda Home & Garden $379.97 477 3.9 12 BULK-ca90249c
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