Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

16 ms

Page Size

25

Current Page

412 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 412 Results Showing 10276 - 10300 of 24441

ID Name Category Price Stock Rating Reviews SKU
10835 Bulk Product ffd41acd Electronics $83.83 456 0.6 74 BULK-87efbdc6
10836 Bulk Product d4331a27 Electronics $487.17 264 2.3 50 BULK-363bf807
10837 Bulk Product c478d6a7 Books $158.71 279 4.3 9 BULK-6c546e36
10838 Bulk Product f91645ee Sports & Outdoors $263.96 468 4.6 56 BULK-5652c606
10839 Bulk Product 86e59340 Books $360.36 329 2.4 58 BULK-f12880ef
10840 Bulk Product 38d14faa Home & Garden $776.29 424 4.8 54 BULK-ecff1dfb
10841 Bulk Product 32363593 Toys & Games $225.98 201 0.5 66 BULK-d1f9ebee
10842 Bulk Product 1cc21d2a Toys & Games $778.22 356 4.7 96 BULK-d0583a92
10843 Bulk Product f0c40e76 Clothing $282.54 324 3.9 37 BULK-830095c2
10844 Bulk Product 3c12e6d8 Books $234.49 403 3.1 96 BULK-b7c1694c
10845 Bulk Product 311eabb1 Books $578.06 429 1.8 43 BULK-7e218919
10846 Bulk Product 7d602bdf Toys & Games $353.17 138 1.8 50 BULK-240951ff
10847 Bulk Product 7f9796b0 Home & Garden $770.80 360 4.7 68 BULK-c2604ab7
10848 Bulk Product 3cead1b7 Toys & Games $240.11 85 4.9 23 BULK-a01d2498
10849 Bulk Product 2898e097 Electronics $102.35 467 2.8 46 BULK-154ace5a
10850 Bulk Product fb35c5ec Sports & Outdoors $965.60 373 3.8 47 BULK-54f33c83
10851 Bulk Product c009c284 Sports & Outdoors $378.08 477 1.2 49 BULK-6eddb602
10852 Bulk Product d0aeb09b Home & Garden $173.89 139 3.6 19 BULK-20d9689f
10853 Bulk Product 58dda536 Books $344.60 363 1.7 48 BULK-a0684fde
10854 Bulk Product 5100e848 Books $661.60 185 4.2 77 BULK-f32d669f
10855 Bulk Product bb4d4c4a Electronics $689.36 219 4.5 31 BULK-7080370a
10856 Bulk Product 777284f1 Clothing $343.52 328 0.6 82 BULK-9ade600d
10857 Bulk Product 6dbf78db Clothing $558.56 438 4.6 37 BULK-56471b9f
10858 Bulk Product ae91b31e Books $792.41 115 3.2 55 BULK-a799f32b
10859 Bulk Product ba540c7d Sports & Outdoors $808.07 166 1.4 91 BULK-d73a3d0a
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