Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

25 ms

Page Size

25

Current Page

651 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 651 Results Showing 16251 - 16275 of 24441

ID Name Category Price Stock Rating Reviews SKU
16810 Bulk Product fd4f387f Toys & Games $625.32 39 4.6 53 BULK-9eb14fa9
16811 Bulk Product 728daae9 Clothing $503.49 123 2.0 41 BULK-03ba53b2
16812 Bulk Product 0b34eaf2 Clothing $89.62 410 2.5 56 BULK-5d429cb8
16813 Bulk Product e85b8a82 Books $250.18 286 4.8 2 BULK-53edb427
16814 Bulk Product 51c83c7c Books $65.92 317 2.4 94 BULK-2ade4c2c
16815 Bulk Product 0fd18531 Home & Garden $187.68 165 1.5 36 BULK-368c81ae
16816 Bulk Product f587a606 Clothing $853.27 336 4.1 4 BULK-487c9106
16817 Bulk Product d6cc99b2 Clothing $822.42 206 4.1 8 BULK-f905a752
16818 Bulk Product 67c3c2d1 Sports & Outdoors $649.67 433 2.1 44 BULK-aa28a4d4
16819 Bulk Product 0acc1a51 Books $726.09 328 1.4 79 BULK-dd4546fb
16820 Bulk Product b6f17f8c Home & Garden $990.29 389 3.3 89 BULK-733bd4e5
16821 Bulk Product 13e989b0 Toys & Games $28.69 335 0.9 13 BULK-cc93c5f9
16822 Bulk Product f368cd9d Home & Garden $421.61 56 3.1 82 BULK-b4eecb61
16823 Bulk Product c139322e Electronics $22.99 488 4.1 37 BULK-d952d576
16824 Bulk Product a59c4806 Books $115.56 195 0.8 8 BULK-3e41d822
16825 Bulk Product 9a3a7394 Toys & Games $846.82 300 4.5 29 BULK-e465ed9a
16826 Bulk Product 8e98efb0 Electronics $988.42 106 1.1 83 BULK-ed7f7be2
16827 Bulk Product 7082b329 Home & Garden $198.70 193 0.7 73 BULK-ff8cccbd
16828 Bulk Product fdd3121d Sports & Outdoors $858.14 136 2.0 91 BULK-1e99cbad
16829 Bulk Product 94a7fb1d Sports & Outdoors $233.53 355 4.9 65 BULK-585e4fcc
16830 Bulk Product 7230562d Sports & Outdoors $407.16 205 3.4 47 BULK-13e54f7e
16831 Bulk Product e72b71cc Electronics $238.64 411 2.1 78 BULK-9fa35a75
16832 Bulk Product eecb7010 Electronics $669.91 292 1.6 13 BULK-0dac1125
16833 Bulk Product a3467cae Books $300.02 81 0.6 2 BULK-04089e62
16834 Bulk Product 771021b9 Clothing $272.52 50 2.5 54 BULK-1019fbb1
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