Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

18 ms

Page Size

25

Current Page

516 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 516 Results Showing 12876 - 12900 of 24441

ID Name Category Price Stock Rating Reviews SKU
13435 Bulk Product bb783f0e Toys & Games $295.54 179 4.0 48 BULK-53d4fe61
13436 Bulk Product 298513e3 Books $94.68 19 4.9 95 BULK-30586332
13437 Bulk Product e7019b89 Books $606.35 196 0.8 78 BULK-96d55bf4
13438 Bulk Product 0dc24b98 Toys & Games $801.94 154 1.3 46 BULK-f5ab81cd
13439 Bulk Product 086c9af9 Toys & Games $142.25 92 2.8 14 BULK-a7c13ce8
13440 Bulk Product a3ffd951 Toys & Games $669.37 498 1.2 50 BULK-5c993332
13441 Bulk Product a588bfff Home & Garden $777.44 431 2.6 69 BULK-ac0057c3
13442 Bulk Product 41d04fcc Books $160.61 44 2.7 87 BULK-3ca411ae
13443 Bulk Product 0b8510b0 Clothing $572.05 30 0.7 56 BULK-d2aeaa2e
13444 Bulk Product 47390d3d Home & Garden $191.46 135 5.0 71 BULK-fb43e7af
13445 Bulk Product 0868866b Toys & Games $813.39 265 4.6 10 BULK-b57eb4aa
13446 Bulk Product aba32e4d Sports & Outdoors $407.52 405 2.2 60 BULK-a246d132
13447 Bulk Product d8b9eb02 Books $277.85 273 1.3 3 BULK-df9c2409
13448 Bulk Product 482f2ac2 Electronics $219.14 69 1.2 84 BULK-75704483
13449 Bulk Product b0ac85fb Books $442.35 219 1.0 25 BULK-48b933a1
13450 Bulk Product 32adfdbe Electronics $571.59 65 4.5 7 BULK-c91b4f51
13451 Bulk Product 3c3f6d28 Toys & Games $799.36 305 0.7 11 BULK-39e8ad49
13452 Bulk Product c525f966 Electronics $184.47 265 4.1 97 BULK-47a1b982
13453 Bulk Product fcb10875 Home & Garden $280.93 323 2.6 15 BULK-fee0cae8
13454 Bulk Product ada8e7dc Books $367.23 358 4.7 85 BULK-30458493
13455 Bulk Product fb80082c Electronics $843.29 480 3.4 88 BULK-139676d2
13456 Bulk Product 95e190e7 Clothing $930.16 408 4.2 25 BULK-d80ffe7d
13457 Bulk Product 139dfde9 Electronics $557.37 274 1.9 40 BULK-86d28c93
13458 Bulk Product 654b2789 Books $96.56 455 2.4 90 BULK-d59262ed
13459 Bulk Product f931b845 Toys & Games $960.25 392 0.6 42 BULK-f4810a35
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