Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

11 ms

Page Size

25

Current Page

130 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 130 Results Showing 3226 - 3250 of 24441

ID Name Category Price Stock Rating Reviews SKU
3621 Elite Clothing Product Classic Clothing $121.51 298 1.2 161 SKU-003621
3622 Professional Automotive Product Advanced Automotive $479.30 408 3.9 922 SKU-003622
3623 Elite Health & Beauty Product Lite Health & Beauty $728.11 42 3.1 424 SKU-003623
3624 Professional Toys & Games Product XL Toys & Games $647.25 236 2.9 949 SKU-003624
3625 Deluxe Toys & Games Product Lite Toys & Games $953.88 465 2.1 937 SKU-003625
3626 Pro Office Supplies Product Lite Office Supplies $738.73 293 2.6 879 SKU-003626
3628 Ultra Toys & Games Product Max Toys & Games $986.10 348 4.5 437 SKU-003628
3630 Ultra Home & Garden Product 2024 Home & Garden $980.75 24 3.4 169 SKU-003630
3631 Mega Office Supplies Product 2024 Office Supplies $293.47 446 3.6 777 SKU-003631
3632 Elite Toys & Games Product Plus Toys & Games $308.22 44 2.8 328 SKU-003632
3633 Super Sports & Outdoors Product Lite Sports & Outdoors $852.37 378 3.6 394 SKU-003633
3634 Standard Home & Garden Product 2024 Home & Garden $351.75 452 1.4 71 SKU-003634
3635 Deluxe Food & Grocery Product Advanced Food & Grocery $409.68 70 1.6 843 SKU-003635
3636 Economy Clothing Product Plus Clothing $535.80 286 3.6 880 SKU-003636
3638 Professional Food & Grocery Product Classic Food & Grocery $949.35 122 2.3 449 SKU-003638
3639 Elite Sports & Outdoors Product Special Edition Sports & Outdoors $842.93 350 4.4 504 SKU-003639
3640 Standard Sports & Outdoors Product Pro Sports & Outdoors $480.87 427 4.0 225 SKU-003640
3641 Elite Food & Grocery Product Advanced Food & Grocery $725.76 410 2.0 519 SKU-003641
3642 Pro Office Supplies Product Pro Office Supplies $486.18 372 2.7 437 SKU-003642
3643 Deluxe Health & Beauty Product Lite Health & Beauty $611.39 360 4.2 662 SKU-003643
3644 Professional Books Product Classic Books $336.28 210 4.2 407 SKU-003644
3645 Elite Electronics Product Lite Electronics $748.50 389 1.3 215 SKU-003645
3646 Elite Clothing Product Plus Clothing $375.39 488 2.2 583 SKU-003646
3647 Standard Books Product Plus Books $20.64 19 3.0 109 SKU-003647
3650 Elite Food & Grocery Product 2024 Food & Grocery $717.76 154 1.5 687 SKU-003650
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