Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

138 ms

Page Size

25

Current Page

807 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 807 Results Showing 20151 - 20175 of 24441

ID Name Category Price Stock Rating Reviews SKU
20710 Bulk Product c3bb745a Sports & Outdoors $265.95 51 2.8 82 BULK-7f7f9df9
20711 Bulk Product bf9c88a5 Home & Garden $490.55 395 1.0 74 BULK-2016521b
20712 Bulk Product fb9004b4 Electronics $859.39 170 0.7 55 BULK-60d09dce
20713 Bulk Product 46a87844 Clothing $139.77 116 2.8 14 BULK-b8bf145d
20714 Bulk Product e87b4e7b Electronics $78.94 488 2.7 54 BULK-fdd14ea5
20715 Bulk Product 13e5da68 Electronics $447.11 176 1.6 54 BULK-3bd39269
20716 Bulk Product 3bdc300d Toys & Games $65.36 45 1.1 14 BULK-63eaaa1e
20717 Bulk Product df400d89 Toys & Games $24.58 151 4.5 0 BULK-0f84e028
20718 Bulk Product 5d4b7596 Home & Garden $960.69 105 1.6 49 BULK-0c50680c
20719 Bulk Product 880a0c43 Home & Garden $261.43 287 4.3 18 BULK-9669f131
20720 Bulk Product f8b947b1 Toys & Games $200.62 274 0.5 71 BULK-8de501fd
20721 Bulk Product 3ca3cd56 Clothing $238.87 118 1.1 94 BULK-2c5a1e83
20722 Bulk Product d3dbba6d Toys & Games $331.08 115 4.0 21 BULK-5d01225f
20723 Bulk Product fbd441d0 Electronics $116.49 268 1.3 82 BULK-98bdcd1b
20724 Bulk Product 7269c72c Books $444.98 118 4.0 86 BULK-6ccf4dc2
20725 Bulk Product 75d149f4 Clothing $935.65 312 4.1 26 BULK-6bcc4f6b
20726 Bulk Product 471ff6b5 Toys & Games $185.18 455 2.6 78 BULK-e04f31ee
20727 Bulk Product fbbb70b4 Sports & Outdoors $156.01 318 4.0 43 BULK-a9c512d5
20728 Bulk Product 9c6c14c5 Sports & Outdoors $818.99 133 3.5 65 BULK-7a65ded1
20729 Bulk Product 3cc9b8d7 Electronics $542.76 168 3.9 58 BULK-43563d97
20730 Bulk Product ef903c1a Books $474.49 151 4.8 1 BULK-900a6116
20731 Bulk Product 6db8ae11 Toys & Games $484.15 336 4.4 18 BULK-8de3e3a9
20732 Bulk Product 1347e2a4 Home & Garden $746.92 228 0.9 45 BULK-3602bc9e
20733 Bulk Product e5051425 Home & Garden $638.30 210 1.5 51 BULK-c5b3fbb3
20734 Bulk Product f6ed1956 Toys & Games $730.80 149 0.3 16 BULK-2e0bae1f
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