Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

17 ms

Page Size

25

Current Page

146 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 146 Results Showing 3626 - 3650 of 24441

ID Name Category Price Stock Rating Reviews SKU
4074 Super Toys & Games Product Special Edition Toys & Games $242.07 184 1.1 858 SKU-004074
4075 Ultra Clothing Product Pro Clothing $537.76 309 1.4 125 SKU-004075
4076 Economy Automotive Product XL Automotive $641.04 348 2.7 551 SKU-004076
4077 Pro Health & Beauty Product Plus Health & Beauty $536.04 164 3.9 682 SKU-004077
4079 Ultra Office Supplies Product Classic Office Supplies $968.07 336 3.4 116 SKU-004079
4080 Economy Automotive Product Max Automotive $616.40 108 5.0 460 SKU-004080
4081 Deluxe Home & Garden Product 2024 Home & Garden $403.81 91 4.1 86 SKU-004081
4082 Super Home & Garden Product 2024 Home & Garden $76.28 214 4.4 438 SKU-004082
4083 Elite Toys & Games Product 2024 Toys & Games $238.79 129 4.4 335 SKU-004083
4087 Elite Sports & Outdoors Product Classic Sports & Outdoors $325.50 115 4.6 254 SKU-004087
4088 Mega Sports & Outdoors Product Plus Sports & Outdoors $924.72 219 3.3 754 SKU-004088
4089 Mega Automotive Product Pro Automotive $942.87 145 4.8 994 SKU-004089
4090 Elite Clothing Product 2024 Clothing $364.64 443 3.5 233 SKU-004090
4091 Ultra Electronics Product Mini Electronics $391.02 484 4.7 169 SKU-004091
4092 Elite Sports & Outdoors Product Advanced Sports & Outdoors $422.78 305 1.3 979 SKU-004092
4095 Pro Food & Grocery Product 2024 Food & Grocery $462.17 477 3.6 652 SKU-004095
4096 Super Books Product Advanced Books $880.89 165 3.4 612 SKU-004096
4097 Premium Clothing Product Mini Clothing $837.31 271 3.1 991 SKU-004097
4098 Economy Sports & Outdoors Product Plus Sports & Outdoors $485.85 25 3.5 116 SKU-004098
4099 Super Health & Beauty Product Plus Health & Beauty $895.53 113 2.5 43 SKU-004099
4100 Ultra Electronics Product Pro Electronics $26.75 68 3.6 288 SKU-004100
4101 Super Clothing Product Classic Clothing $881.95 458 3.8 516 SKU-004101
4102 Pro Clothing Product Special Edition Clothing $294.55 366 2.3 96 SKU-004102
4103 Elite Automotive Product Mini Automotive $291.52 338 2.9 628 SKU-004103
4104 Economy Clothing Product Classic Clothing $747.16 202 4.2 601 SKU-004104
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