Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

38 ms

Page Size

25

Current Page

673 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 673 Results Showing 16801 - 16825 of 24441

ID Name Category Price Stock Rating Reviews SKU
17360 Bulk Product e2e9c924 Electronics $871.42 371 0.2 20 BULK-b203d789
17361 Bulk Product 47a2bb61 Clothing $80.69 481 0.4 69 BULK-6a50e51f
17362 Bulk Product 4062ea64 Books $803.20 83 1.5 59 BULK-b1248efa
17363 Bulk Product 45ff0ae7 Clothing $163.45 122 4.2 28 BULK-80e4cd60
17364 Bulk Product 1a6bcd04 Books $837.09 68 0.9 29 BULK-335983f3
17365 Bulk Product f01b22a0 Toys & Games $714.39 319 3.2 20 BULK-fe6e9dff
17366 Bulk Product 3e58ba6f Home & Garden $603.89 241 0.0 60 BULK-fb7e77ea
17367 Bulk Product a303c388 Home & Garden $149.42 496 0.5 48 BULK-7ae1c527
17368 Bulk Product dd7bbcee Electronics $371.68 291 4.3 95 BULK-4d30ce2c
17369 Bulk Product 406f427d Electronics $576.68 432 3.6 52 BULK-64ccc36b
17370 Bulk Product 22315cac Electronics $605.85 446 3.4 11 BULK-f67f2e72
17371 Bulk Product 3618d95c Sports & Outdoors $966.15 140 2.1 50 BULK-c8d67511
17372 Bulk Product e4062cf8 Books $765.09 86 1.2 1 BULK-549ef055
17373 Bulk Product 5949be41 Clothing $628.93 350 4.9 68 BULK-f0c69adc
17374 Bulk Product ea99ad7e Sports & Outdoors $296.16 91 3.2 38 BULK-3a3244fb
17375 Bulk Product 8511c2b5 Sports & Outdoors $798.20 77 3.8 92 BULK-b2038226
17376 Bulk Product 1e627b7f Toys & Games $651.19 423 3.1 5 BULK-12604f85
17377 Bulk Product 1d3ffcdb Sports & Outdoors $600.74 149 4.4 62 BULK-87ce5b92
17378 Bulk Product 5b4e3688 Sports & Outdoors $714.81 146 2.8 5 BULK-df517049
17379 Bulk Product 47c5a1c9 Books $513.34 301 4.7 4 BULK-341934ae
17380 Bulk Product 2c033ccc Books $199.24 248 0.7 56 BULK-466db059
17381 Bulk Product 0aea37e2 Toys & Games $32.64 469 2.4 95 BULK-a4c4187b
17382 Bulk Product 52b10ad9 Electronics $409.36 122 2.2 13 BULK-853869d2
17383 Bulk Product 8f929cb8 Home & Garden $331.07 31 4.4 63 BULK-32c2f2a0
17384 Bulk Product b21babcd Books $672.98 104 0.3 30 BULK-07f67542
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