Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

140 ms

Page Size

25

Current Page

135 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 135 Results Showing 3351 - 3375 of 24441

ID Name Category Price Stock Rating Reviews SKU
3755 Economy Books Product Lite Books $212.92 467 4.4 701 SKU-003755
3756 Mega Sports & Outdoors Product Mini Sports & Outdoors $525.66 471 2.8 851 SKU-003756
3757 Deluxe Automotive Product Classic Automotive $980.32 219 3.2 246 SKU-003757
3759 Super Office Supplies Product Classic Office Supplies $204.31 439 1.8 963 SKU-003759
3760 Standard Electronics Product Pro Electronics $636.43 300 4.4 924 SKU-003760
3764 Mega Electronics Product Classic Electronics $130.72 238 4.9 477 SKU-003764
3765 Pro Electronics Product Plus Electronics $835.41 203 3.8 481 SKU-003765
3767 Economy Automotive Product 2024 Automotive $899.64 222 4.1 420 SKU-003767
3769 Professional Sports & Outdoors Product XL Sports & Outdoors $615.80 333 2.8 409 SKU-003769
3770 Standard Toys & Games Product Mini Toys & Games $461.80 499 2.8 326 SKU-003770
3772 Pro Electronics Product Pro Electronics $308.59 398 3.9 508 SKU-003772
3773 Deluxe Automotive Product Plus Automotive $709.56 343 2.4 890 SKU-003773
3774 Super Sports & Outdoors Product Max Sports & Outdoors $590.34 261 4.0 40 SKU-003774
3775 Premium Clothing Product Max Clothing $548.85 236 3.9 587 SKU-003775
3777 Super Health & Beauty Product Pro Health & Beauty $759.85 296 1.5 675 SKU-003777
3779 Standard Sports & Outdoors Product Pro Sports & Outdoors $458.41 439 1.2 179 SKU-003779
3780 Elite Automotive Product Lite Automotive $316.28 71 3.2 727 SKU-003780
3783 Super Books Product Max Books $405.42 47 2.7 312 SKU-003783
3784 Mega Office Supplies Product Special Edition Office Supplies $885.15 136 2.9 572 SKU-003784
3785 Super Food & Grocery Product Lite Food & Grocery $512.64 234 4.6 84 SKU-003785
3786 Mega Office Supplies Product Plus Office Supplies $500.01 53 3.1 488 SKU-003786
3787 Ultra Office Supplies Product Lite Office Supplies $399.84 220 2.0 879 SKU-003787
3788 Economy Office Supplies Product 2024 Office Supplies $281.86 462 4.9 742 SKU-003788
3789 Premium Food & Grocery Product Mini Food & Grocery $605.81 10 1.9 675 SKU-003789
3790 Premium Clothing Product Classic Clothing $906.33 113 4.1 677 SKU-003790
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