Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

9 ms

Page Size

25

Current Page

85 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 85 Results Showing 2101 - 2125 of 24441

ID Name Category Price Stock Rating Reviews SKU
2365 Economy Clothing Product Plus Clothing $546.76 59 3.1 524 SKU-002365
2366 Elite Books Product Mini Books $779.53 22 1.0 201 SKU-002366
2368 Economy Automotive Product Classic Automotive $405.16 449 4.2 927 SKU-002368
2369 Mega Office Supplies Product 2024 Office Supplies $876.32 456 2.3 959 SKU-002369
2370 Ultra Health & Beauty Product XL Health & Beauty $862.15 85 2.7 898 SKU-002370
2371 Elite Books Product XL Books $398.66 2 4.5 192 SKU-002371
2372 Pro Office Supplies Product Mini Office Supplies $722.42 314 3.9 556 SKU-002372
2373 Premium Food & Grocery Product Classic Food & Grocery $99.58 492 4.9 489 SKU-002373
2374 Pro Health & Beauty Product XL Health & Beauty $539.02 229 2.5 588 SKU-002374
2375 Mega Books Product Lite Books $821.13 495 1.6 662 SKU-002375
2376 Elite Toys & Games Product Advanced Toys & Games $661.24 484 4.4 971 SKU-002376
2377 Mega Clothing Product Special Edition Clothing $784.48 376 3.4 422 SKU-002377
2378 Professional Clothing Product Max Clothing $843.99 364 4.1 340 SKU-002378
2379 Premium Toys & Games Product Lite Toys & Games $134.19 324 1.6 891 SKU-002379
2380 Pro Books Product Pro Books $804.61 191 2.2 647 SKU-002380
2381 Deluxe Toys & Games Product XL Toys & Games $789.97 130 2.8 556 SKU-002381
2382 Elite Sports & Outdoors Product Plus Sports & Outdoors $315.17 328 4.7 164 SKU-002382
2383 Super Sports & Outdoors Product Advanced Sports & Outdoors $538.74 162 4.4 47 SKU-002383
2384 Deluxe Clothing Product Lite Clothing $670.26 329 4.6 992 SKU-002384
2385 Mega Toys & Games Product XL Toys & Games $448.69 46 3.5 281 SKU-002385
2388 Pro Home & Garden Product Special Edition Home & Garden $669.62 210 4.8 83 SKU-002388
2389 Mega Automotive Product XL Automotive $759.21 447 3.0 468 SKU-002389
2390 Mega Automotive Product Advanced Automotive $193.20 241 1.5 481 SKU-002390
2391 Ultra Health & Beauty Product Classic Health & Beauty $309.68 211 1.0 42 SKU-002391
2392 Elite Health & Beauty Product 2024 Health & Beauty $331.14 420 1.2 159 SKU-002392
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