Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

17 ms

Page Size

25

Current Page

42 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 42 Results Showing 1026 - 1050 of 24441

ID Name Category Price Stock Rating Reviews SKU
1157 Super Sports & Outdoors Product Special Edition Sports & Outdoors $143.71 489 1.8 301 SKU-001157
1159 Premium Food & Grocery Product Advanced Food & Grocery $225.15 254 3.7 455 SKU-001159
1160 Professional Books Product Mini Books $270.32 239 2.7 677 SKU-001160
1161 Super Home & Garden Product XL Home & Garden $92.62 228 1.0 691 SKU-001161
1162 Ultra Health & Beauty Product Lite Health & Beauty $565.88 247 4.2 949 SKU-001162
1163 Professional Clothing Product Pro Clothing $147.33 89 3.7 719 SKU-001163
1164 Super Food & Grocery Product Classic Food & Grocery $161.87 303 4.9 574 SKU-001164
1165 Elite Books Product Max Books $21.11 450 4.6 173 SKU-001165
1166 Economy Home & Garden Product Classic Home & Garden $745.66 379 4.4 640 SKU-001166
1167 Pro Health & Beauty Product Special Edition Health & Beauty $479.86 348 2.9 296 SKU-001167
1168 Economy Toys & Games Product Lite Toys & Games $356.62 385 3.5 76 SKU-001168
1169 Mega Toys & Games Product Special Edition Toys & Games $467.91 20 4.6 728 SKU-001169
1170 Standard Health & Beauty Product Mini Health & Beauty $514.33 396 2.5 457 SKU-001170
1171 Pro Electronics Product Special Edition Electronics $518.28 238 2.6 518 SKU-001171
1172 Deluxe Electronics Product Max Electronics $69.98 276 3.6 770 SKU-001172
1173 Economy Electronics Product Mini Electronics $295.99 173 4.2 90 SKU-001173
1174 Deluxe Automotive Product Max Automotive $494.05 444 3.5 917 SKU-001174
1175 Elite Clothing Product XL Clothing $332.75 383 1.9 744 SKU-001175
1176 Deluxe Toys & Games Product XL Toys & Games $159.32 92 2.5 513 SKU-001176
1178 Premium Books Product 2024 Books $709.38 243 4.0 638 SKU-001178
1179 Premium Books Product Lite Books $834.76 218 4.1 189 SKU-001179
1180 Premium Automotive Product Lite Automotive $464.49 182 3.8 212 SKU-001180
1181 Ultra Clothing Product Classic Clothing $29.25 0 1.1 35 SKU-001181
1182 Standard Electronics Product XL Electronics $433.20 417 3.3 842 SKU-001182
1185 Mega Food & Grocery Product Plus Food & Grocery $279.97 38 2.7 707 SKU-001185
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