Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

33 ms

Page Size

25

Current Page

719 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 719 Results Showing 17951 - 17975 of 24441

ID Name Category Price Stock Rating Reviews SKU
18510 Bulk Product 52ace88a Books $837.45 454 1.2 80 BULK-9721162f
18511 Bulk Product 593058e5 Toys & Games $529.47 201 2.5 55 BULK-2f78e3e9
18512 Bulk Product b9173c70 Toys & Games $730.60 102 4.3 0 BULK-76fb75bd
18513 Bulk Product 5a330590 Sports & Outdoors $775.19 365 3.7 14 BULK-ff6f586a
18514 Bulk Product 954145e7 Sports & Outdoors $987.83 361 4.9 6 BULK-958ba16e
18515 Bulk Product 5352af30 Toys & Games $332.85 319 1.1 34 BULK-4c55fee8
18516 Bulk Product 63fa2d4e Electronics $545.18 29 1.3 23 BULK-6c2394e4
18517 Bulk Product 6d979ab7 Books $889.52 467 4.3 99 BULK-b2ac5bac
18518 Bulk Product 06d428b1 Electronics $658.06 54 3.9 61 BULK-685ed7a3
18519 Bulk Product 35d7cc4f Toys & Games $401.51 10 4.9 79 BULK-e1cf3641
18520 Bulk Product 3a85f040 Sports & Outdoors $888.64 384 1.0 80 BULK-6a9be7b0
18521 Bulk Product a7c94b13 Toys & Games $183.44 484 0.5 80 BULK-56b6a28f
18522 Bulk Product ce267a20 Clothing $925.96 295 4.1 95 BULK-bf1b1a89
18523 Bulk Product 31b5b373 Sports & Outdoors $798.79 57 4.4 44 BULK-f4d154a8
18524 Bulk Product ade44236 Home & Garden $178.43 490 2.7 0 BULK-51df5002
18525 Bulk Product b68736b1 Sports & Outdoors $873.22 67 4.1 59 BULK-7669453d
18526 Bulk Product e9818391 Books $307.77 492 3.4 96 BULK-febe42dc
18527 Bulk Product 550c87ae Electronics $627.14 235 4.3 20 BULK-0a1d3acc
18528 Bulk Product 797e48d4 Electronics $682.25 204 0.6 35 BULK-ab9de7d2
18529 Bulk Product 29827381 Home & Garden $801.17 495 1.5 24 BULK-78fe4104
18530 Bulk Product 10405357 Books $703.97 118 2.7 30 BULK-8d8f0574
18531 Bulk Product 3e41fd51 Sports & Outdoors $748.93 70 0.1 70 BULK-e533a6d7
18532 Bulk Product f7416ed5 Clothing $460.95 8 1.6 98 BULK-1df37f67
18533 Bulk Product 2079a3fc Home & Garden $526.77 55 1.9 65 BULK-071be8d4
18534 Bulk Product 132a325e Sports & Outdoors $441.54 109 3.6 22 BULK-3318f1f9
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