Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

27 ms

Page Size

25

Current Page

98 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 98 Results Showing 2426 - 2450 of 24441

ID Name Category Price Stock Rating Reviews SKU
2723 Elite Toys & Games Product Special Edition Toys & Games $564.50 248 2.4 41 SKU-002723
2724 Deluxe Home & Garden Product Advanced Home & Garden $224.35 476 2.3 127 SKU-002724
2725 Premium Automotive Product Classic Automotive $938.63 485 3.8 787 SKU-002725
2726 Super Food & Grocery Product Pro Food & Grocery $956.39 145 4.8 756 SKU-002726
2727 Standard Office Supplies Product Max Office Supplies $611.27 287 3.6 669 SKU-002727
2728 Standard Electronics Product Max Electronics $106.51 230 3.9 639 SKU-002728
2729 Professional Toys & Games Product Special Edition Toys & Games $181.65 341 3.7 399 SKU-002729
2731 Professional Office Supplies Product Pro Office Supplies $688.07 396 3.7 460 SKU-002731
2732 Professional Automotive Product Plus Automotive $57.74 150 3.2 402 SKU-002732
2733 Pro Books Product Mini Books $989.06 16 4.5 565 SKU-002733
2734 Professional Office Supplies Product Advanced Office Supplies $646.84 311 2.6 947 SKU-002734
2735 Pro Toys & Games Product 2024 Toys & Games $825.35 10 1.8 776 SKU-002735
2736 Standard Clothing Product Mini Clothing $149.28 433 4.9 814 SKU-002736
2738 Ultra Office Supplies Product Plus Office Supplies $462.34 340 2.5 755 SKU-002738
2740 Economy Toys & Games Product Max Toys & Games $378.11 449 2.5 343 SKU-002740
2741 Pro Office Supplies Product Mini Office Supplies $813.81 222 3.2 783 SKU-002741
2742 Ultra Toys & Games Product Lite Toys & Games $948.50 477 3.5 326 SKU-002742
2743 Economy Office Supplies Product Mini Office Supplies $635.16 248 3.0 378 SKU-002743
2744 Elite Food & Grocery Product Plus Food & Grocery $954.28 284 1.7 653 SKU-002744
2745 Ultra Sports & Outdoors Product Pro Sports & Outdoors $808.50 102 1.5 774 SKU-002745
2746 Deluxe Electronics Product Lite Electronics $358.60 368 4.1 47 SKU-002746
2747 Mega Automotive Product Max Automotive $999.12 161 3.7 858 SKU-002747
2748 Pro Toys & Games Product Pro Toys & Games $248.21 204 4.4 993 SKU-002748
2749 Professional Sports & Outdoors Product Pro Sports & Outdoors $747.46 234 3.9 129 SKU-002749
2750 Mega Health & Beauty Product 2024 Health & Beauty $519.82 2 3.6 100 SKU-002750
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