Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

29 ms

Page Size

25

Current Page

297 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 297 Results Showing 7401 - 7425 of 24441

ID Name Category Price Stock Rating Reviews SKU
7960 Bulk Product cc984e67 Toys & Games $82.25 335 2.5 27 BULK-0720b38c
7961 Bulk Product 2a60ba83 Clothing $610.25 361 5.0 78 BULK-482ec2c5
7962 Bulk Product da8db9c9 Books $245.79 347 4.9 20 BULK-1c642cc7
7963 Bulk Product d4099c82 Toys & Games $340.07 43 4.3 24 BULK-2dcdc164
7964 Bulk Product d56a22ca Books $683.81 56 3.7 49 BULK-314d4bbd
7965 Bulk Product ed6dc6d0 Home & Garden $539.14 190 5.0 20 BULK-44f9e48c
7966 Bulk Product f9e190bf Sports & Outdoors $409.81 29 4.6 38 BULK-26e070a0
7967 Bulk Product 36dc36f3 Electronics $761.82 305 0.6 52 BULK-9fae5e51
7968 Bulk Product 34bde415 Clothing $883.90 48 0.7 0 BULK-2f5bfb82
7969 Bulk Product 5953bf10 Electronics $467.50 443 4.1 53 BULK-c27483cd
7970 Bulk Product 99d83042 Sports & Outdoors $1,001.35 280 4.6 0 BULK-1ee30444
7971 Bulk Product b3c19ba1 Electronics $92.86 444 2.8 90 BULK-1a762360
7972 Bulk Product 09c85b21 Books $933.09 276 4.2 84 BULK-2d22d34e
7973 Bulk Product 10043a8d Books $661.99 58 4.2 74 BULK-fba7c83c
7974 Bulk Product 4141e326 Electronics $846.11 391 2.4 18 BULK-cf31c0af
7975 Bulk Product 77f6dabc Home & Garden $1,000.58 51 1.8 22 BULK-f7f6c267
7976 Bulk Product d0587502 Sports & Outdoors $280.26 487 0.1 28 BULK-695408b2
7977 Bulk Product b9c530dc Clothing $57.16 196 0.5 35 BULK-6ea46584
7978 Bulk Product 8905938b Home & Garden $52.08 71 3.9 45 BULK-c69a0283
7979 Bulk Product 394b227a Home & Garden $959.84 369 1.2 88 BULK-be1e2466
7980 Bulk Product dadf99b0 Books $429.82 298 2.4 91 BULK-a96d3e07
7981 Bulk Product fcbe18c5 Electronics $19.34 499 2.6 74 BULK-0d19f8b5
7982 Bulk Product 9aa82458 Books $575.49 349 0.8 3 BULK-24b0ac8b
7983 Bulk Product 0f620f29 Electronics $541.25 214 1.6 28 BULK-c1062e64
7984 Bulk Product b87b2258 Home & Garden $594.84 498 3.8 51 BULK-82e9e78a
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