Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

86 ms

Page Size

25

Current Page

41 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 41 Results Showing 1001 - 1025 of 24441

ID Name Category Price Stock Rating Reviews SKU
1127 Super Clothing Product Advanced Clothing $151.59 170 3.7 649 SKU-001127
1128 Pro Electronics Product XL Electronics $146.15 163 2.9 367 SKU-001128
1129 Deluxe Home & Garden Product Plus Home & Garden $873.68 132 1.5 753 SKU-001129
1130 Super Sports & Outdoors Product Pro Sports & Outdoors $154.17 427 3.4 598 SKU-001130
1131 Professional Home & Garden Product XL Home & Garden $391.05 464 4.3 886 SKU-001131
1132 Deluxe Electronics Product 2024 Electronics $901.33 71 4.3 511 SKU-001132
1133 Mega Toys & Games Product Mini Toys & Games $493.90 160 3.9 158 SKU-001133
1134 Mega Sports & Outdoors Product Mini Sports & Outdoors $781.40 19 1.6 563 SKU-001134
1135 Super Food & Grocery Product Pro Food & Grocery $851.50 55 3.6 231 SKU-001135
1136 Elite Electronics Product Mini Electronics $522.42 353 1.5 35 SKU-001136
1138 Premium Toys & Games Product Pro Toys & Games $632.88 338 1.3 622 SKU-001138
1139 Deluxe Clothing Product Classic Clothing $697.12 307 1.2 781 SKU-001139
1141 Elite Toys & Games Product Plus Toys & Games $749.64 479 5.0 657 SKU-001141
1142 Premium Clothing Product 2024 Clothing $598.14 296 2.1 461 SKU-001142
1144 Standard Sports & Outdoors Product XL Sports & Outdoors $881.78 97 1.1 791 SKU-001144
1145 Economy Office Supplies Product 2024 Office Supplies $286.68 278 3.7 697 SKU-001145
1146 Premium Automotive Product Lite Automotive $223.68 182 3.1 423 SKU-001146
1148 Pro Books Product Classic Books $405.58 224 3.9 713 SKU-001148
1149 Elite Sports & Outdoors Product Plus Sports & Outdoors $976.29 335 3.2 912 SKU-001149
1150 Premium Health & Beauty Product Mini Health & Beauty $184.48 363 1.3 285 SKU-001150
1151 Deluxe Books Product Lite Books $219.99 210 4.2 184 SKU-001151
1152 Standard Health & Beauty Product XL Health & Beauty $23.32 136 1.4 844 SKU-001152
1153 Deluxe Books Product XL Books $307.22 152 3.6 790 SKU-001153
1155 Elite Food & Grocery Product Classic Food & Grocery $303.05 469 4.3 96 SKU-001155
1156 Premium Automotive Product Special Edition Automotive $202.71 474 2.8 963 SKU-001156
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