Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

15 ms

Page Size

25

Current Page

674 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 674 Results Showing 16826 - 16850 of 24441

ID Name Category Price Stock Rating Reviews SKU
17385 Bulk Product a88c4e0b Toys & Games $225.89 40 3.6 2 BULK-55342c0a
17386 Bulk Product 5768584e Home & Garden $115.92 236 4.4 30 BULK-2dbeeba5
17387 Bulk Product 043fb8c8 Sports & Outdoors $313.82 125 2.8 13 BULK-f0641683
17388 Bulk Product b9205201 Toys & Games $491.57 448 2.6 99 BULK-b6297138
17389 Bulk Product 0f5009dc Toys & Games $553.36 38 2.3 70 BULK-3f135807
17390 Bulk Product 054dbf98 Home & Garden $239.83 46 4.3 1 BULK-525c2f46
17391 Bulk Product d90477aa Clothing $693.78 448 3.6 89 BULK-12e9d689
17392 Bulk Product a68a642e Home & Garden $240.58 70 3.6 31 BULK-cd1c38d4
17393 Bulk Product 397ea2fd Sports & Outdoors $17.88 353 0.7 51 BULK-c45dd7f6
17394 Bulk Product 92d8850f Sports & Outdoors $89.66 186 4.9 47 BULK-454ff31b
17395 Bulk Product 162e9114 Home & Garden $18.34 369 4.8 50 BULK-261a3aa1
17396 Bulk Product 7ab38096 Clothing $727.16 36 4.3 29 BULK-dd19016b
17397 Bulk Product 25fdddf2 Books $983.89 413 4.0 74 BULK-66cb1292
17398 Bulk Product e666b852 Books $419.41 250 2.6 90 BULK-2fd0a72d
17399 Bulk Product c1cf2de1 Electronics $386.23 441 3.3 20 BULK-a18c54ad
17400 Bulk Product 0775e285 Electronics $756.85 40 2.2 90 BULK-024f5def
17401 Bulk Product 0e291bed Toys & Games $349.45 57 0.0 16 BULK-0eee1cd5
17402 Bulk Product 896404ab Sports & Outdoors $685.27 18 2.6 27 BULK-5bf1abe3
17403 Bulk Product d9615ea6 Home & Garden $572.10 450 3.0 83 BULK-62b850fb
17404 Bulk Product 36807627 Books $626.57 295 2.2 34 BULK-b189afb2
17405 Bulk Product 5baaab1d Sports & Outdoors $764.48 151 3.2 33 BULK-ec9a3f99
17406 Bulk Product 6ca13f05 Toys & Games $842.26 126 3.7 76 BULK-66b0e604
17407 Bulk Product 7a814ac0 Home & Garden $22.14 312 2.5 39 BULK-03ff4f5e
17408 Bulk Product adc4d3c8 Home & Garden $169.16 210 2.6 26 BULK-5b71776d
17409 Bulk Product 7acb44a9 Sports & Outdoors $423.81 194 4.6 67 BULK-3bda72c4
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