Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

9 ms

Page Size

25

Current Page

46 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 46 Results Showing 1126 - 1150 of 24441

ID Name Category Price Stock Rating Reviews SKU
1274 Deluxe Clothing Product Plus Clothing $502.84 133 4.8 102 SKU-001274
1275 Economy Office Supplies Product Max Office Supplies $377.26 377 4.9 458 SKU-001275
1276 Super Home & Garden Product Lite Home & Garden $634.84 143 2.2 258 SKU-001276
1277 Super Health & Beauty Product 2024 Health & Beauty $758.63 350 2.4 593 SKU-001277
1279 Ultra Toys & Games Product 2024 Toys & Games $423.34 405 1.4 815 SKU-001279
1280 Economy Home & Garden Product Advanced Home & Garden $210.17 212 4.5 316 SKU-001280
1281 Deluxe Electronics Product Max Electronics $162.08 321 3.6 823 SKU-001281
1282 Super Clothing Product Plus Clothing $316.41 491 2.0 175 SKU-001282
1283 Standard Office Supplies Product Lite Office Supplies $72.51 92 4.4 403 SKU-001283
1284 Premium Electronics Product Classic Electronics $133.24 428 2.3 659 SKU-001284
1285 Ultra Toys & Games Product 2024 Toys & Games $256.73 373 3.6 854 SKU-001285
1286 Ultra Health & Beauty Product Mini Health & Beauty $88.47 423 1.6 150 SKU-001286
1287 Deluxe Automotive Product Max Automotive $877.19 382 3.7 780 SKU-001287
1288 Ultra Clothing Product Max Clothing $366.91 292 2.3 273 SKU-001288
1289 Pro Automotive Product 2024 Automotive $369.08 155 3.8 955 SKU-001289
1290 Deluxe Books Product Advanced Books $460.01 302 3.1 498 SKU-001290
1291 Premium Clothing Product Classic Clothing $358.36 62 4.5 479 SKU-001291
1292 Elite Books Product Advanced Books $907.84 163 3.8 459 SKU-001292
1293 Elite Clothing Product Lite Clothing $441.87 160 1.9 417 SKU-001293
1294 Mega Office Supplies Product 2024 Office Supplies $215.78 138 3.3 203 SKU-001294
1295 Economy Sports & Outdoors Product Special Edition Sports & Outdoors $378.57 178 3.8 293 SKU-001295
1296 Ultra Electronics Product Advanced Electronics $390.82 488 3.0 280 SKU-001296
1297 Professional Electronics Product Plus Electronics $314.00 230 4.7 376 SKU-001297
1298 Ultra Toys & Games Product Plus Toys & Games $743.74 433 1.3 835 SKU-001298
1300 Professional Books Product Classic Books $278.36 482 1.0 661 SKU-001300
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