Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

14 ms

Page Size

25

Current Page

852 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 852 Results Showing 21276 - 21300 of 24441

ID Name Category Price Stock Rating Reviews SKU
21835 Bulk Product 2d0eb5b9 Books $817.10 232 0.1 13 BULK-b74acdb0
21836 Bulk Product 3b7a1fcf Books $245.28 299 2.7 12 BULK-d591afb3
21837 Bulk Product d94ffca8 Toys & Games $848.74 191 2.4 21 BULK-5aab8908
21838 Bulk Product 5a5fc30f Sports & Outdoors $720.44 387 4.2 41 BULK-9097f6fb
21839 Bulk Product 30c031df Home & Garden $816.18 298 3.3 87 BULK-edf6ec4a
21840 Bulk Product 7c65a805 Electronics $357.27 289 1.7 10 BULK-fc744883
21841 Bulk Product 3d150fbe Clothing $683.55 77 2.8 23 BULK-f77a7ab6
21842 Bulk Product b6139ab9 Home & Garden $833.75 253 2.4 28 BULK-cfea0c9c
21843 Bulk Product 1570f0e0 Clothing $336.53 111 0.8 87 BULK-ec51fc9d
21844 Bulk Product 938dbf2e Sports & Outdoors $904.32 178 1.3 10 BULK-8bf4bd9c
21845 Bulk Product 946a20fb Clothing $70.44 499 4.8 41 BULK-6ed8ae90
21846 Bulk Product 4bbff319 Clothing $171.41 147 3.9 53 BULK-c0fdd9da
21847 Bulk Product dc31f85f Home & Garden $964.03 346 1.7 79 BULK-c0c79c24
21848 Bulk Product d8a7e8c6 Home & Garden $576.73 200 1.4 48 BULK-565d93fb
21849 Bulk Product fae9c79c Home & Garden $568.09 414 1.3 0 BULK-aa8873de
21850 Bulk Product be509338 Sports & Outdoors $968.63 358 4.7 75 BULK-e5ee2fe7
21851 Bulk Product c44e0816 Toys & Games $752.68 253 4.5 21 BULK-2e2bf5d4
21852 Bulk Product 555e99ca Electronics $86.94 220 3.6 95 BULK-775fd57c
21853 Bulk Product c19cc763 Electronics $418.55 36 3.0 63 BULK-3f58de67
21854 Bulk Product 8c4fbcd7 Books $724.73 408 4.4 94 BULK-2b2887d0
21855 Bulk Product 8ddc7d00 Clothing $668.93 441 3.7 88 BULK-67be7a11
21856 Bulk Product 16474c60 Books $518.61 187 2.4 15 BULK-18f1c18b
21857 Bulk Product 4fb00ae2 Home & Garden $57.70 178 0.5 16 BULK-16c4681e
21858 Bulk Product d8f9108f Clothing $371.66 35 2.3 41 BULK-be6bce0c
21859 Bulk Product 0a55729f Toys & Games $90.68 167 1.0 37 BULK-224eba35
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