Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

10 ms

Page Size

25

Current Page

84 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 84 Results Showing 2076 - 2100 of 24441

ID Name Category Price Stock Rating Reviews SKU
2337 Mega Electronics Product Lite Electronics $105.15 255 1.8 377 SKU-002337
2338 Pro Home & Garden Product Special Edition Home & Garden $532.37 327 3.7 992 SKU-002338
2339 Elite Office Supplies Product Classic Office Supplies $769.07 365 1.3 690 SKU-002339
2340 Elite Books Product Special Edition Books $843.21 52 5.0 879 SKU-002340
2341 Premium Automotive Product Mini Automotive $186.90 18 1.7 104 SKU-002341
2344 Super Food & Grocery Product Lite Food & Grocery $981.81 495 4.7 162 SKU-002344
2345 Standard Home & Garden Product Plus Home & Garden $835.84 455 1.3 112 SKU-002345
2346 Pro Electronics Product XL Electronics $861.14 405 1.2 797 SKU-002346
2347 Super Office Supplies Product Special Edition Office Supplies $338.41 264 2.5 327 SKU-002347
2348 Super Office Supplies Product Mini Office Supplies $706.75 369 1.5 212 SKU-002348
2349 Mega Home & Garden Product Max Home & Garden $313.30 337 1.2 30 SKU-002349
2350 Premium Toys & Games Product Special Edition Toys & Games $349.45 389 1.2 96 SKU-002350
2351 Economy Health & Beauty Product Advanced Health & Beauty $967.47 89 5.0 616 SKU-002351
2352 Standard Office Supplies Product Classic Office Supplies $445.88 414 1.7 727 SKU-002352
2353 Economy Home & Garden Product Pro Home & Garden $954.12 111 3.6 257 SKU-002353
2354 Ultra Electronics Product Max Electronics $956.90 387 2.8 348 SKU-002354
2355 Deluxe Books Product Max Books $366.85 306 3.1 914 SKU-002355
2356 Deluxe Automotive Product Classic Automotive $308.63 370 1.2 137 SKU-002356
2357 Ultra Home & Garden Product Lite Home & Garden $723.01 242 1.7 706 SKU-002357
2358 Standard Office Supplies Product Mini Office Supplies $744.10 169 3.0 343 SKU-002358
2359 Standard Office Supplies Product Max Office Supplies $111.13 418 4.6 405 SKU-002359
2360 Pro Office Supplies Product Lite Office Supplies $708.21 289 1.8 421 SKU-002360
2362 Professional Health & Beauty Product Special Edition Health & Beauty $472.96 429 4.9 262 SKU-002362
2363 Super Clothing Product 2024 Clothing $557.23 341 4.6 999 SKU-002363
2364 Ultra Toys & Games Product Classic Toys & Games $575.17 397 1.9 767 SKU-002364
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