Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

16 ms

Page Size

25

Current Page

881 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 881 Results Showing 22001 - 22025 of 24441

ID Name Category Price Stock Rating Reviews SKU
22560 Bulk Product fdb65472 Clothing $922.81 51 1.2 16 BULK-9989706e
22561 Bulk Product a57bfe93 Books $127.72 438 4.4 52 BULK-9a449239
22562 Bulk Product 4c696d33 Toys & Games $32.11 120 3.1 14 BULK-c7ad2ff9
22563 Bulk Product 1f6f8627 Electronics $528.90 362 3.7 44 BULK-97e1f3ce
22564 Bulk Product b9f4fb56 Toys & Games $119.97 206 2.1 38 BULK-1bd52624
22565 Bulk Product 0b1a8bad Electronics $272.31 51 1.2 17 BULK-ba43f903
22566 Bulk Product ad11f312 Home & Garden $928.15 185 2.5 88 BULK-07a391d5
22567 Bulk Product 6646c5dc Home & Garden $622.34 390 1.5 29 BULK-64714223
22568 Bulk Product 0c446e70 Clothing $98.48 188 1.1 69 BULK-0d1af4d4
22569 Bulk Product f8aa9632 Home & Garden $837.73 299 1.0 10 BULK-6f1859d4
22570 Bulk Product 237a7479 Sports & Outdoors $755.22 447 1.9 34 BULK-5af63d25
22571 Bulk Product ff39d50e Sports & Outdoors $439.70 274 0.7 16 BULK-c19f7b3c
22572 Bulk Product 29b936ab Home & Garden $435.67 481 3.7 22 BULK-3225a6e5
22573 Bulk Product e3defcc6 Books $347.14 17 3.3 45 BULK-cff27d3a
22574 Bulk Product c638a7fd Electronics $525.56 168 2.1 66 BULK-f531cf87
22575 Bulk Product 52e3f060 Sports & Outdoors $282.07 478 0.6 18 BULK-9519d225
22576 Bulk Product bfa0c616 Toys & Games $838.44 145 1.2 23 BULK-2fe7d85e
22577 Bulk Product 45dbf2b1 Electronics $821.55 105 3.4 72 BULK-34e2d50a
22578 Bulk Product 88dc175b Books $81.81 396 3.7 28 BULK-50f9a263
22579 Bulk Product 71627ba0 Sports & Outdoors $463.29 425 3.9 69 BULK-3ecceabf
22580 Bulk Product edd53130 Sports & Outdoors $972.36 73 4.6 78 BULK-ea2155a6
22581 Bulk Product 728e3570 Toys & Games $870.60 333 0.3 39 BULK-d1d38d39
22582 Bulk Product f1280575 Electronics $928.71 465 3.0 6 BULK-a86c57cc
22583 Bulk Product 9515d2f6 Electronics $595.23 308 4.0 96 BULK-22701e80
22584 Bulk Product 99b80535 Toys & Games $945.91 406 1.7 52 BULK-41b08225
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