Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

39 ms

Page Size

25

Current Page

202 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 202 Results Showing 5026 - 5050 of 24441

ID Name Category Price Stock Rating Reviews SKU
5585 Bulk Product db24d9f4 Books $73.30 472 1.0 20 BULK-5149a661
5586 Bulk Product eb0bf769 Sports & Outdoors $531.61 27 2.1 83 BULK-6e7bab3c
5587 Bulk Product d3724bac Electronics $706.72 164 4.5 45 BULK-7d98b10a
5588 Bulk Product b31a5baf Toys & Games $37.52 257 2.8 81 BULK-31a25d65
5589 Bulk Product 2134df15 Toys & Games $753.38 40 0.7 78 BULK-680b9b84
5590 Bulk Product 5b9d3243 Home & Garden $548.37 427 1.9 27 BULK-e44eaece
5591 Bulk Product 94f207a9 Electronics $23.48 212 4.7 66 BULK-06ddc4db
5592 Bulk Product 7f2883c3 Home & Garden $824.90 27 4.9 8 BULK-9990c6fb
5593 Bulk Product c448244a Electronics $513.00 268 2.6 57 BULK-44db641b
5594 Bulk Product 1370a776 Clothing $448.97 353 3.7 48 BULK-d49141d1
5595 Bulk Product 757573a6 Clothing $364.16 75 2.7 57 BULK-2db3b587
5596 Bulk Product 117eb49a Electronics $345.16 273 4.1 17 BULK-012134ca
5597 Bulk Product df737d0c Home & Garden $790.25 54 1.9 30 BULK-20438fbc
5598 Bulk Product a81717ee Clothing $235.34 20 1.4 86 BULK-3f17a964
5599 Bulk Product 1b8f3627 Clothing $720.04 396 2.2 22 BULK-3d1c0a9d
5600 Bulk Product d804b42e Sports & Outdoors $232.19 366 0.6 13 BULK-2da0bffb
5601 Bulk Product fe2462f8 Home & Garden $871.36 326 1.0 37 BULK-2eb0f611
5602 Bulk Product 550089b1 Sports & Outdoors $208.56 451 0.2 86 BULK-a2253818
5603 Bulk Product 0a07a9ff Home & Garden $735.43 393 3.5 44 BULK-55eb4b7c
5604 Bulk Product c92dcf9d Toys & Games $919.12 50 1.8 91 BULK-9fa20ea2
5605 Bulk Product 60aab798 Clothing $342.35 238 0.8 10 BULK-0678333c
5606 Bulk Product e7232bcf Sports & Outdoors $1,009.44 112 0.8 82 BULK-a7748af3
5607 Bulk Product f7dab0f2 Clothing $65.57 370 4.5 94 BULK-ded8795f
5608 Bulk Product 96801551 Clothing $610.28 360 4.2 37 BULK-e5959612
5609 Bulk Product b831bf5b Toys & Games $877.95 203 0.7 15 BULK-68119194
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