Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

20 ms

Page Size

25

Current Page

650 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 650 Results Showing 16226 - 16250 of 24441

ID Name Category Price Stock Rating Reviews SKU
16785 Bulk Product 8863907e Sports & Outdoors $90.06 146 2.2 56 BULK-5e7e1cfa
16786 Bulk Product f41e4565 Books $30.14 153 2.7 71 BULK-e34d62cb
16787 Bulk Product 94d0684c Home & Garden $75.21 308 2.5 41 BULK-46bbfa22
16788 Bulk Product 5bd6296e Sports & Outdoors $468.50 496 3.5 93 BULK-a3657009
16789 Bulk Product ec90bebf Clothing $639.40 436 1.4 14 BULK-de53f305
16790 Bulk Product bdc94622 Clothing $275.94 488 2.8 77 BULK-d42c0273
16791 Bulk Product b307b2b6 Books $429.39 321 0.7 27 BULK-d7ba4f92
16792 Bulk Product 3e000468 Books $522.92 280 1.7 80 BULK-57e11e94
16793 Bulk Product 77708064 Toys & Games $830.85 152 1.4 47 BULK-8224bcaf
16794 Bulk Product 4a8cc5ff Home & Garden $80.27 143 1.4 28 BULK-25ed7094
16795 Bulk Product b210c54e Clothing $330.78 17 1.7 52 BULK-b60ac8a3
16796 Bulk Product 43480f1b Toys & Games $145.89 62 1.1 36 BULK-7acfa77b
16797 Bulk Product 694e67c2 Clothing $895.43 477 3.6 37 BULK-44011e0e
16798 Bulk Product 933bbd8b Toys & Games $357.18 32 2.5 86 BULK-bb1422eb
16799 Bulk Product d08d8066 Toys & Games $940.22 376 2.8 12 BULK-2ed9f047
16800 Bulk Product 7d7d7039 Sports & Outdoors $849.25 263 4.9 98 BULK-96358b46
16801 Bulk Product fdad6fa3 Toys & Games $741.55 333 4.7 27 BULK-a6402337
16802 Bulk Product 5f924673 Electronics $833.85 46 4.2 21 BULK-fb4b6f7a
16803 Bulk Product d7f8ce4e Toys & Games $254.91 212 3.8 32 BULK-b6db2aff
16804 Bulk Product 06b87bb3 Clothing $712.20 300 0.5 63 BULK-9d2a1878
16805 Bulk Product 19582606 Electronics $111.57 390 3.4 32 BULK-26bcd951
16806 Bulk Product e4c85251 Electronics $823.62 416 1.5 46 BULK-d0bb4c27
16807 Bulk Product c64dd9af Books $693.82 73 1.3 25 BULK-8dfd428c
16808 Bulk Product 5e4fd5e6 Clothing $490.96 153 1.6 53 BULK-575b98b2
16809 Bulk Product 460aeb8e Electronics $175.67 343 4.4 69 BULK-78aaff3c
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