Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

20 ms

Page Size

25

Current Page

38 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 38 Results Showing 926 - 950 of 24441

ID Name Category Price Stock Rating Reviews SKU
1041 Premium Electronics Product Classic Electronics $820.99 50 4.3 854 SKU-001041
1042 Elite Toys & Games Product Classic Toys & Games $645.04 167 4.7 267 SKU-001042
1043 Elite Health & Beauty Product Special Edition Health & Beauty $182.90 133 2.9 380 SKU-001043
1044 Standard Electronics Product Pro Electronics $480.76 42 1.3 47 SKU-001044
1045 Premium Books Product Max Books $213.60 340 2.2 667 SKU-001045
1046 Standard Home & Garden Product XL Home & Garden $505.25 439 1.5 574 SKU-001046
1047 Standard Food & Grocery Product Max Food & Grocery $658.65 464 1.3 766 SKU-001047
1048 Mega Automotive Product Lite Automotive $120.25 261 2.5 265 SKU-001048
1049 Super Home & Garden Product Pro Home & Garden $757.73 362 3.1 912 SKU-001049
1050 Premium Books Product Pro Books $824.57 126 1.8 849 SKU-001050
1051 Economy Office Supplies Product Max Office Supplies $909.78 81 2.8 356 SKU-001051
1052 Mega Office Supplies Product Plus Office Supplies $547.15 335 2.4 230 SKU-001052
1053 Elite Electronics Product Mini Electronics $55.59 124 4.6 662 SKU-001053
1054 Professional Automotive Product Lite Automotive $928.01 214 1.7 517 SKU-001054
1055 Pro Health & Beauty Product Plus Health & Beauty $699.40 434 1.5 808 SKU-001055
1056 Economy Electronics Product Advanced Electronics $926.45 411 1.6 574 SKU-001056
1057 Professional Food & Grocery Product 2024 Food & Grocery $70.10 133 1.0 298 SKU-001057
1059 Standard Books Product Special Edition Books $97.10 433 1.0 901 SKU-001059
1061 Ultra Clothing Product Special Edition Clothing $718.70 269 3.1 526 SKU-001061
1062 Professional Home & Garden Product XL Home & Garden $737.42 90 3.5 695 SKU-001062
1064 Premium Toys & Games Product XL Toys & Games $224.38 379 2.3 0 SKU-001064
1065 Mega Home & Garden Product Advanced Home & Garden $499.27 121 2.3 586 SKU-001065
1066 Elite Clothing Product Mini Clothing $816.89 199 3.4 607 SKU-001066
1067 Elite Sports & Outdoors Product Advanced Sports & Outdoors $585.66 384 3.3 65 SKU-001067
1068 Economy Clothing Product Pro Clothing $928.88 310 2.0 783 SKU-001068
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