Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

16 ms

Page Size

25

Current Page

292 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 292 Results Showing 7276 - 7300 of 24441

ID Name Category Price Stock Rating Reviews SKU
7835 Bulk Product dc2aed79 Clothing $95.86 47 0.2 47 BULK-f1ac9aeb
7836 Bulk Product 7c5ff2d4 Books $556.36 87 4.6 18 BULK-a6684d35
7837 Bulk Product be3074b6 Electronics $926.23 341 1.2 58 BULK-af74141e
7838 Bulk Product c12420a9 Books $463.33 70 1.9 52 BULK-b9d2a566
7839 Bulk Product 03b4416e Clothing $235.36 259 4.8 49 BULK-c5376cff
7840 Bulk Product 72faff0d Sports & Outdoors $859.34 438 0.3 92 BULK-5c25b712
7841 Bulk Product 5b66a9d2 Electronics $151.21 1 4.1 7 BULK-1a06211a
7842 Bulk Product a3e485dc Books $625.49 405 3.6 96 BULK-08223676
7843 Bulk Product f19201f2 Clothing $593.41 431 3.0 32 BULK-dec75f39
7844 Bulk Product 747f1ed6 Toys & Games $149.41 329 1.7 69 BULK-a98288cd
7845 Bulk Product 4bf2d34f Toys & Games $270.94 457 2.3 90 BULK-1ddaa395
7846 Bulk Product 91c16610 Electronics $919.13 2 2.3 35 BULK-332dcafb
7847 Bulk Product d2ac3754 Electronics $745.70 68 0.6 33 BULK-cb0322d7
7848 Bulk Product fcf5bf7a Toys & Games $725.49 183 3.1 1 BULK-d32fc9a8
7849 Bulk Product 2f0866ff Home & Garden $619.14 12 4.3 64 BULK-700e3afc
7850 Bulk Product a50b9d15 Home & Garden $607.79 15 0.3 13 BULK-fefdbcd4
7851 Bulk Product fc702abf Books $856.98 74 1.5 99 BULK-a86a9c3f
7852 Bulk Product 36538316 Books $39.11 232 1.5 29 BULK-8b62fdde
7853 Bulk Product 34056eab Clothing $944.40 322 0.6 56 BULK-3c11263e
7854 Bulk Product f7784997 Clothing $455.22 399 1.9 23 BULK-96ffa533
7855 Bulk Product efc6b717 Electronics $740.49 45 0.6 53 BULK-d4002112
7856 Bulk Product 5081de2b Books $774.62 329 1.1 42 BULK-f2277dc5
7857 Bulk Product 37c27601 Sports & Outdoors $43.74 4 4.4 1 BULK-ef1d03fb
7858 Bulk Product 208a1eb6 Electronics $251.20 105 3.3 54 BULK-c0bb5184
7859 Bulk Product 1c8b37dd Toys & Games $706.56 158 0.0 37 BULK-b82874b9
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