Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

14 ms

Page Size

50

Current Page

24 / 489

Total Records

24441

Items per page: 25 50 100 200

Page 24 Results Showing 1151 - 1200 of 24441

ID Name Category Price Stock Rating Reviews SKU
1301 Premium Clothing Product Advanced Clothing $385.62 101 4.9 914 SKU-001301
1302 Ultra Clothing Product Lite Clothing $358.08 352 4.9 265 SKU-001302
1303 Economy Electronics Product Lite Electronics $563.14 303 3.0 928 SKU-001303
1304 Pro Electronics Product Max Electronics $160.29 468 1.4 253 SKU-001304
1305 Elite Home & Garden Product Plus Home & Garden $254.35 106 1.5 385 SKU-001305
1306 Ultra Electronics Product Classic Electronics $431.15 444 2.6 246 SKU-001306
1307 Economy Health & Beauty Product Special Edition Health & Beauty $367.00 270 4.5 979 SKU-001307
1308 Elite Home & Garden Product Pro Home & Garden $720.92 118 3.9 346 SKU-001308
1309 Professional Health & Beauty Product 2024 Health & Beauty $734.71 346 2.3 998 SKU-001309
1311 Ultra Books Product Classic Books $542.76 190 4.7 401 SKU-001311
1312 Economy Office Supplies Product Plus Office Supplies $176.60 237 2.0 521 SKU-001312
1313 Pro Office Supplies Product 2024 Office Supplies $83.96 48 4.7 41 SKU-001313
1314 Deluxe Electronics Product 2024 Electronics $853.18 377 4.5 630 SKU-001314
1315 Deluxe Electronics Product Plus Electronics $674.88 450 2.4 441 SKU-001315
1316 Economy Books Product Classic Books $859.83 491 3.8 376 SKU-001316
1318 Mega Automotive Product Lite Automotive $340.46 271 2.9 784 SKU-001318
1319 Pro Food & Grocery Product Advanced Food & Grocery $822.50 428 2.5 509 SKU-001319
1321 Pro Food & Grocery Product Special Edition Food & Grocery $480.56 256 2.0 860 SKU-001321
1322 Mega Automotive Product Plus Automotive $78.80 413 2.3 818 SKU-001322
1323 Mega Books Product Plus Books $73.06 316 3.9 998 SKU-001323
1324 Pro Office Supplies Product Lite Office Supplies $474.48 152 3.5 191 SKU-001324
1325 Professional Electronics Product 2024 Electronics $816.48 420 1.0 30 SKU-001325
1326 Super Home & Garden Product Advanced Home & Garden $248.61 49 3.7 620 SKU-001326
1327 Premium Books Product 2024 Books $720.14 79 4.4 597 SKU-001327
1328 Mega Automotive Product Special Edition Automotive $180.03 405 2.5 400 SKU-001328
1330 Standard Health & Beauty Product Max Health & Beauty $481.45 438 4.7 199 SKU-001330
1332 Deluxe Sports & Outdoors Product Advanced Sports & Outdoors $698.91 3 2.6 692 SKU-001332
1333 Economy Food & Grocery Product Advanced Food & Grocery $341.32 204 3.7 639 SKU-001333
1334 Super Clothing Product Special Edition Clothing $217.64 49 4.4 392 SKU-001334
1335 Ultra Sports & Outdoors Product Mini Sports & Outdoors $642.01 298 1.1 807 SKU-001335
1336 Elite Clothing Product Max Clothing $815.53 191 2.9 73 SKU-001336
1337 Professional Books Product Pro Books $530.74 263 1.6 983 SKU-001337
1338 Mega Home & Garden Product Special Edition Home & Garden $718.30 163 2.5 368 SKU-001338
1339 Pro Office Supplies Product Pro Office Supplies $363.35 341 2.6 505 SKU-001339
1341 Standard Books Product Lite Books $192.45 240 3.5 478 SKU-001341
1342 Economy Automotive Product Special Edition Automotive $624.59 171 1.8 219 SKU-001342
1343 Ultra Toys & Games Product XL Toys & Games $704.58 479 2.0 574 SKU-001343
1344 Pro Home & Garden Product XL Home & Garden $865.44 169 5.0 634 SKU-001344
1345 Standard Clothing Product Pro Clothing $172.63 68 3.6 843 SKU-001345
1346 Ultra Food & Grocery Product Classic Food & Grocery $356.07 191 2.4 87 SKU-001346
1347 Ultra Toys & Games Product Advanced Toys & Games $333.29 255 4.8 311 SKU-001347
1348 Mega Health & Beauty Product Mini Health & Beauty $722.72 85 1.8 13 SKU-001348
1350 Professional Office Supplies Product Mini Office Supplies $188.27 44 3.2 16 SKU-001350
1352 Super Sports & Outdoors Product Classic Sports & Outdoors $201.95 259 1.1 316 SKU-001352
1353 Professional Toys & Games Product Plus Toys & Games $764.40 111 3.8 546 SKU-001353
1354 Standard Food & Grocery Product Lite Food & Grocery $704.98 84 3.6 394 SKU-001354
1355 Super Sports & Outdoors Product Special Edition Sports & Outdoors $468.33 139 1.4 277 SKU-001355
1356 Professional Food & Grocery Product Advanced Food & Grocery $464.59 416 3.0 401 SKU-001356
1357 Super Electronics Product Advanced Electronics $788.28 124 3.8 644 SKU-001357
1358 Standard Clothing Product 2024 Clothing $198.25 343 4.2 756 SKU-001358
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