Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

23 ms

Page Size

25

Current Page

327 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 327 Results Showing 8151 - 8175 of 24441

ID Name Category Price Stock Rating Reviews SKU
8710 Bulk Product 3374bdd9 Toys & Games $651.87 194 3.2 59 BULK-123e0bb6
8711 Bulk Product acd51975 Electronics $319.88 280 4.3 89 BULK-99f2b691
8712 Bulk Product 70cb8e0a Toys & Games $574.11 333 1.9 77 BULK-5e0bd3ea
8713 Bulk Product a8e3ff61 Toys & Games $936.06 249 4.1 60 BULK-23677662
8714 Bulk Product b5ce585e Sports & Outdoors $369.39 204 1.4 95 BULK-a7e7560a
8715 Bulk Product 1555913f Toys & Games $750.43 103 1.8 79 BULK-a93215ef
8716 Bulk Product 672f6c98 Home & Garden $214.11 464 2.5 69 BULK-e9b6b1b4
8717 Bulk Product 23563af1 Sports & Outdoors $401.49 65 1.0 57 BULK-ebc46f90
8718 Bulk Product 5aee7d50 Home & Garden $476.07 228 2.1 35 BULK-4e5c061d
8719 Bulk Product a188a842 Toys & Games $872.88 226 3.4 13 BULK-13102a2e
8720 Bulk Product a4b37cd9 Home & Garden $625.30 327 4.6 94 BULK-63ec64ab
8721 Bulk Product 931f0b88 Clothing $140.83 86 2.5 7 BULK-6ea97752
8722 Bulk Product c339d510 Electronics $647.73 134 4.5 17 BULK-c6f1885b
8723 Bulk Product e14a5d3a Home & Garden $148.31 174 1.4 9 BULK-f88a5a29
8724 Bulk Product 4ab75299 Home & Garden $840.75 309 0.2 99 BULK-254d55e0
8725 Bulk Product b18aa0ad Clothing $541.08 214 3.2 0 BULK-de816201
8726 Bulk Product 906ec3fb Home & Garden $231.68 384 3.6 92 BULK-52622e21
8727 Bulk Product 27c99cf7 Clothing $578.17 210 4.1 57 BULK-f6e75bca
8728 Bulk Product ddf0dd4b Home & Garden $252.61 68 3.2 69 BULK-3afceade
8729 Bulk Product 4f4b9371 Sports & Outdoors $161.99 80 2.0 64 BULK-c2a84777
8730 Bulk Product b93ce3db Sports & Outdoors $130.93 410 4.2 52 BULK-1f639926
8731 Bulk Product e6201bb1 Clothing $149.96 1 3.6 99 BULK-990ca702
8732 Bulk Product 1d811817 Books $779.33 437 3.8 74 BULK-f0aa7b35
8733 Bulk Product 494fbda6 Clothing $54.00 153 4.3 96 BULK-51df5b40
8734 Bulk Product a20ab515 Electronics $27.37 42 0.4 86 BULK-4074ac32
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