Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

17 ms

Page Size

25

Current Page

169 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 169 Results Showing 4201 - 4225 of 24441

ID Name Category Price Stock Rating Reviews SKU
4738 Economy Books Product Advanced Books $476.61 472 3.4 848 SKU-004738
4739 Professional Health & Beauty Product Classic Health & Beauty $663.30 101 1.8 725 SKU-004739
4740 Pro Books Product Lite Books $299.21 327 4.5 576 SKU-004740
4741 Elite Office Supplies Product Max Office Supplies $624.06 484 1.8 892 SKU-004741
4742 Ultra Sports & Outdoors Product Pro Sports & Outdoors $142.54 419 1.7 535 SKU-004742
4745 Economy Home & Garden Product XL Home & Garden $848.15 105 1.1 694 SKU-004745
4746 Standard Office Supplies Product Mini Office Supplies $294.13 163 1.2 948 SKU-004746
4747 Premium Books Product Max Books $940.54 110 4.7 36 SKU-004747
4748 Pro Home & Garden Product Advanced Home & Garden $752.41 67 1.3 431 SKU-004748
4749 Economy Office Supplies Product Special Edition Office Supplies $884.13 26 1.1 853 SKU-004749
4750 Economy Automotive Product Plus Automotive $457.89 18 1.9 507 SKU-004750
4751 Professional Food & Grocery Product Pro Food & Grocery $474.94 351 2.4 846 SKU-004751
4752 Mega Clothing Product Mini Clothing $919.91 0 2.2 446 SKU-004752
4753 Economy Clothing Product Plus Clothing $960.34 219 1.5 328 SKU-004753
4754 Ultra Home & Garden Product Plus Home & Garden $807.95 105 2.9 156 SKU-004754
4755 Super Home & Garden Product Lite Home & Garden $334.86 162 4.6 104 SKU-004755
4756 Premium Books Product Mini Books $983.87 379 4.6 994 SKU-004756
4757 Standard Electronics Product Mini Electronics $957.20 170 1.3 826 SKU-004757
4758 Pro Books Product Special Edition Books $460.57 118 4.9 666 SKU-004758
4759 Super Sports & Outdoors Product Advanced Sports & Outdoors $561.37 180 3.6 426 SKU-004759
4760 Pro Clothing Product Max Clothing $704.85 258 4.1 2 SKU-004760
4761 Mega Office Supplies Product Plus Office Supplies $350.53 220 4.7 480 SKU-004761
4762 Economy Clothing Product Advanced Clothing $746.97 186 1.1 761 SKU-004762
4763 Deluxe Clothing Product Advanced Clothing $417.96 431 4.6 237 SKU-004763
4764 Deluxe Electronics Product Classic Electronics $68.09 419 1.7 707 SKU-004764
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