Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

9 ms

Page Size

25

Current Page

75 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 75 Results Showing 1851 - 1875 of 24441

ID Name Category Price Stock Rating Reviews SKU
2090 Super Office Supplies Product Advanced Office Supplies $525.08 180 3.1 901 SKU-002090
2091 Deluxe Books Product Classic Books $67.30 84 2.9 476 SKU-002091
2092 Mega Clothing Product Advanced Clothing $552.05 109 1.8 89 SKU-002092
2094 Economy Electronics Product Pro Electronics $453.80 31 3.7 276 SKU-002094
2095 Premium Clothing Product Special Edition Clothing $515.76 412 2.1 838 SKU-002095
2096 Standard Clothing Product Classic Clothing $425.42 268 1.6 173 SKU-002096
2097 Economy Automotive Product Mini Automotive $215.07 224 2.9 582 SKU-002097
2098 Deluxe Health & Beauty Product Max Health & Beauty $691.99 327 2.7 220 SKU-002098
2100 Super Books Product Lite Books $150.33 345 2.4 229 SKU-002100
2101 Ultra Toys & Games Product Lite Toys & Games $155.66 91 1.1 693 SKU-002101
2102 Deluxe Health & Beauty Product Plus Health & Beauty $735.12 332 1.8 474 SKU-002102
2103 Pro Office Supplies Product Advanced Office Supplies $481.73 463 2.4 585 SKU-002103
2104 Deluxe Clothing Product Pro Clothing $245.71 365 1.6 663 SKU-002104
2105 Pro Books Product Max Books $70.07 144 1.6 282 SKU-002105
2106 Super Office Supplies Product Advanced Office Supplies $428.15 208 1.9 975 SKU-002106
2107 Elite Office Supplies Product Plus Office Supplies $910.23 269 1.3 632 SKU-002107
2108 Economy Health & Beauty Product XL Health & Beauty $350.27 244 4.7 462 SKU-002108
2109 Professional Office Supplies Product Max Office Supplies $155.23 219 3.3 465 SKU-002109
2110 Super Health & Beauty Product Special Edition Health & Beauty $242.83 359 3.6 712 SKU-002110
2111 Deluxe Automotive Product Special Edition Automotive $952.61 294 1.2 615 SKU-002111
2112 Professional Office Supplies Product Max Office Supplies $73.01 433 5.0 955 SKU-002112
2113 Pro Automotive Product Plus Automotive $156.48 497 4.8 272 SKU-002113
2114 Pro Home & Garden Product Pro Home & Garden $949.87 83 4.3 486 SKU-002114
2116 Pro Clothing Product Mini Clothing $789.87 57 3.0 209 SKU-002116
2117 Premium Home & Garden Product Special Edition Home & Garden $324.69 346 2.2 880 SKU-002117
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