Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

20 ms

Page Size

25

Current Page

195 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 195 Results Showing 4851 - 4875 of 24441

ID Name Category Price Stock Rating Reviews SKU
5410 Bulk Product 219d77e9 Clothing $733.09 320 1.7 30 BULK-a201b2d8
5411 Bulk Product a50e2c7f Home & Garden $458.50 375 0.3 52 BULK-8d3faf1d
5412 Bulk Product b5b8ec77 Toys & Games $95.79 215 2.4 89 BULK-f05bbcb7
5413 Bulk Product 8a9729e4 Home & Garden $655.33 37 1.3 21 BULK-f7940ec7
5414 Bulk Product 724679b5 Clothing $983.22 247 0.5 47 BULK-7d13a698
5415 Bulk Product bc59fe93 Books $1,006.60 473 1.1 22 BULK-c3c4b63a
5416 Bulk Product f17d9fb8 Books $246.73 281 1.1 45 BULK-3a552a57
5417 Bulk Product 7def050b Home & Garden $377.66 485 4.5 31 BULK-ef47b9c4
5418 Bulk Product 7eb8a71e Sports & Outdoors $647.43 77 4.7 9 BULK-dd1604bc
5419 Bulk Product 31d3c1c8 Home & Garden $433.73 325 2.0 19 BULK-9c61ed96
5420 Bulk Product 8fa9a9f4 Books $372.11 458 3.1 18 BULK-ee793c4a
5421 Bulk Product 3abd9bc0 Home & Garden $847.58 281 2.1 73 BULK-54658aaf
5422 Bulk Product 2ec215fd Clothing $418.77 242 0.6 37 BULK-0caf7f4d
5423 Bulk Product eed6ccf1 Books $647.77 156 1.4 38 BULK-c6ac96d1
5424 Bulk Product 94519d97 Sports & Outdoors $360.38 97 3.4 1 BULK-3bc7eaad
5425 Bulk Product aa0a02d8 Sports & Outdoors $586.85 433 0.9 88 BULK-fa249bc5
5426 Bulk Product 47919b59 Electronics $588.75 255 2.7 35 BULK-7ffca7ea
5427 Bulk Product bfef71e3 Books $644.69 67 2.4 9 BULK-709ded86
5428 Bulk Product 813d302c Clothing $847.08 299 1.7 88 BULK-097f55d0
5429 Bulk Product 90294c26 Sports & Outdoors $344.29 134 3.5 25 BULK-f7707301
5430 Bulk Product d65e34a7 Toys & Games $120.37 480 3.8 32 BULK-d4dd6085
5431 Bulk Product daaf8ac3 Toys & Games $884.15 290 0.6 20 BULK-21c61884
5432 Bulk Product 0c9c5880 Clothing $770.27 416 4.3 64 BULK-19cd0cbe
5433 Bulk Product b4127d19 Home & Garden $276.83 469 0.1 22 BULK-5b0744c7
5434 Bulk Product 23e2efbe Home & Garden $494.87 184 3.5 25 BULK-307edda2
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