Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

14 ms

Page Size

25

Current Page

326 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 326 Results Showing 8126 - 8150 of 24441

ID Name Category Price Stock Rating Reviews SKU
8685 Bulk Product 845f24d1 Sports & Outdoors $180.46 228 3.3 79 BULK-3abfd69d
8686 Bulk Product f1a70eb2 Sports & Outdoors $830.06 466 4.5 15 BULK-8edbe18e
8687 Bulk Product 890e3f27 Toys & Games $484.03 177 0.5 78 BULK-541d98dc
8688 Bulk Product 0367091a Toys & Games $606.35 303 5.0 74 BULK-cfe31784
8689 Bulk Product ac4f0283 Toys & Games $801.28 29 2.7 38 BULK-0778a6b3
8690 Bulk Product 1bcd6f62 Toys & Games $118.79 392 0.7 45 BULK-c7713180
8691 Bulk Product 5395d2cb Clothing $79.61 137 4.9 74 BULK-571ad4e0
8692 Bulk Product ab12b198 Books $829.87 144 0.3 31 BULK-da293a43
8693 Bulk Product b849da9a Electronics $68.13 271 1.1 13 BULK-15fca790
8694 Bulk Product b3b178b7 Books $490.44 127 2.4 20 BULK-6ee25552
8695 Bulk Product 229af3d0 Home & Garden $41.47 13 2.5 32 BULK-a3b00dd4
8696 Bulk Product e0237ac4 Clothing $46.51 110 0.7 34 BULK-15f6c4e4
8697 Bulk Product 853dfdd2 Toys & Games $224.39 371 2.9 66 BULK-e2410457
8698 Bulk Product f25338b1 Electronics $759.76 279 4.9 89 BULK-96985a6b
8699 Bulk Product 6c27528f Clothing $81.88 459 4.3 66 BULK-47632004
8700 Bulk Product ad76ab9c Toys & Games $507.35 483 4.4 47 BULK-4ef67042
8701 Bulk Product da35d0a7 Electronics $42.19 466 0.4 33 BULK-4d3f9b7b
8702 Bulk Product 331c2487 Books $697.31 143 3.3 5 BULK-6206088d
8703 Bulk Product ef24a1c7 Clothing $459.64 183 0.8 48 BULK-6a2a5ad1
8704 Bulk Product 0dbfc6bf Toys & Games $260.03 239 0.3 53 BULK-fd5b0466
8705 Bulk Product 916718ec Sports & Outdoors $796.79 41 2.2 23 BULK-2405ee74
8706 Bulk Product f90729ac Books $930.16 11 3.3 22 BULK-09a23243
8707 Bulk Product 4b2787e9 Electronics $492.75 84 2.7 52 BULK-48680ed3
8708 Bulk Product 8a1ae9fd Clothing $876.16 48 0.6 68 BULK-87d30500
8709 Bulk Product a1c03810 Clothing $979.30 54 1.0 85 BULK-76a9d3ce
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