Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

13 ms

Page Size

25

Current Page

133 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 133 Results Showing 3301 - 3325 of 24441

ID Name Category Price Stock Rating Reviews SKU
3702 Premium Automotive Product Plus Automotive $570.47 474 2.5 634 SKU-003702
3703 Pro Food & Grocery Product XL Food & Grocery $86.91 54 3.6 921 SKU-003703
3705 Professional Clothing Product Advanced Clothing $677.70 410 3.0 739 SKU-003705
3706 Mega Automotive Product Plus Automotive $584.86 483 2.4 118 SKU-003706
3707 Elite Food & Grocery Product XL Food & Grocery $465.72 410 1.3 811 SKU-003707
3708 Elite Office Supplies Product Max Office Supplies $777.46 80 2.6 166 SKU-003708
3709 Ultra Electronics Product Pro Electronics $281.73 417 2.9 967 SKU-003709
3710 Mega Automotive Product Plus Automotive $903.15 34 1.7 282 SKU-003710
3711 Elite Automotive Product Advanced Automotive $525.67 195 2.6 439 SKU-003711
3712 Ultra Automotive Product Lite Automotive $836.18 434 3.5 998 SKU-003712
3713 Ultra Home & Garden Product Advanced Home & Garden $780.15 319 4.9 608 SKU-003713
3714 Deluxe Toys & Games Product Pro Toys & Games $747.44 178 4.4 209 SKU-003714
3715 Standard Sports & Outdoors Product Mini Sports & Outdoors $423.03 323 2.9 749 SKU-003715
3716 Ultra Sports & Outdoors Product Pro Sports & Outdoors $551.26 229 2.6 219 SKU-003716
3717 Super Electronics Product Special Edition Electronics $123.10 147 4.7 211 SKU-003717
3718 Elite Books Product Max Books $582.01 285 2.1 698 SKU-003718
3719 Standard Food & Grocery Product 2024 Food & Grocery $428.01 236 1.7 625 SKU-003719
3720 Elite Office Supplies Product Lite Office Supplies $872.10 42 2.3 5 SKU-003720
3721 Deluxe Office Supplies Product Max Office Supplies $828.00 75 3.4 807 SKU-003721
3722 Super Office Supplies Product Max Office Supplies $126.95 262 1.1 121 SKU-003722
3723 Standard Automotive Product XL Automotive $632.29 299 4.5 13 SKU-003723
3724 Super Automotive Product 2024 Automotive $940.22 307 1.4 440 SKU-003724
3725 Ultra Clothing Product Plus Clothing $500.10 192 4.3 811 SKU-003725
3726 Pro Health & Beauty Product XL Health & Beauty $210.64 119 1.2 797 SKU-003726
3727 Elite Clothing Product Classic Clothing $616.33 490 1.8 464 SKU-003727
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