Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

23 ms

Page Size

25

Current Page

592 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 592 Results Showing 14776 - 14800 of 24441

ID Name Category Price Stock Rating Reviews SKU
15335 Bulk Product d13da669 Clothing $679.30 326 1.1 98 BULK-66bdc0f4
15336 Bulk Product 518d4fa3 Clothing $823.05 289 1.6 98 BULK-4bd4f0a2
15337 Bulk Product 78a3b800 Books $854.93 118 0.7 46 BULK-56320694
15338 Bulk Product e82792e8 Electronics $195.86 233 4.2 1 BULK-0047b16a
15339 Bulk Product 133bd806 Toys & Games $716.20 426 4.9 49 BULK-49aa210a
15340 Bulk Product 21be3d42 Electronics $295.85 476 2.3 45 BULK-d27d7bad
15341 Bulk Product f47e9e96 Books $865.25 417 1.5 8 BULK-3347a28e
15342 Bulk Product 5ad88716 Clothing $563.58 403 3.2 97 BULK-43600f65
15343 Bulk Product c7294be1 Sports & Outdoors $185.58 196 0.3 3 BULK-6890a42d
15344 Bulk Product cd5bb378 Home & Garden $446.60 438 1.1 6 BULK-9b395136
15345 Bulk Product 76656f81 Toys & Games $775.33 31 1.0 34 BULK-7c5d3313
15346 Bulk Product 8dae351b Clothing $196.06 344 0.2 55 BULK-86e72ea7
15347 Bulk Product 12211616 Clothing $441.92 72 1.1 39 BULK-fdb4495e
15348 Bulk Product c75395a1 Sports & Outdoors $188.21 457 1.1 29 BULK-e8bb0ad6
15349 Bulk Product 54c99398 Sports & Outdoors $359.80 17 4.0 61 BULK-6ec12e0d
15350 Bulk Product fe39ec5e Electronics $629.00 245 0.2 22 BULK-5c749abb
15351 Bulk Product 69fa1b14 Home & Garden $83.45 214 4.7 23 BULK-a63d1878
15352 Bulk Product b284ee44 Toys & Games $92.15 105 0.1 12 BULK-79f20c2b
15353 Bulk Product a8a2c284 Sports & Outdoors $186.50 121 1.1 15 BULK-e70aa3aa
15354 Bulk Product 0f0fbdcc Sports & Outdoors $576.46 224 4.6 95 BULK-77563f93
15355 Bulk Product c92fbcb0 Electronics $366.28 204 1.7 98 BULK-10daf68c
15356 Bulk Product 21342f9a Toys & Games $561.42 454 4.7 87 BULK-29480e60
15357 Bulk Product 4988a91a Toys & Games $987.84 156 2.4 68 BULK-f3ccb746
15358 Bulk Product fffc5990 Electronics $295.62 239 1.0 4 BULK-841914c5
15359 Bulk Product 728a9581 Clothing $46.93 283 0.8 63 BULK-c0c00bdc
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