Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

15 ms

Page Size

25

Current Page

694 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 694 Results Showing 17326 - 17350 of 24441

ID Name Category Price Stock Rating Reviews SKU
17885 Bulk Product 0ec4bb45 Electronics $876.61 158 1.9 48 BULK-0fccecbc
17886 Bulk Product c6a6f35a Toys & Games $308.47 54 3.0 96 BULK-952e58c2
17887 Bulk Product 31cc6ce8 Clothing $479.57 364 2.7 55 BULK-2de55317
17888 Bulk Product b5141dbb Electronics $663.01 477 0.3 11 BULK-aa04fb4c
17889 Bulk Product fdc0274f Books $103.04 343 0.3 76 BULK-7f783b99
17890 Bulk Product 0dd49af1 Home & Garden $894.45 49 0.9 81 BULK-93025288
17891 Bulk Product 602794dc Sports & Outdoors $538.96 457 3.2 8 BULK-2aadf246
17892 Bulk Product dbb76fec Books $142.39 17 1.4 23 BULK-6c151e4c
17893 Bulk Product 7a63bb34 Toys & Games $702.36 294 4.5 66 BULK-d322fb71
17894 Bulk Product cdbcf14c Home & Garden $761.44 76 4.3 23 BULK-00e6a89d
17895 Bulk Product 66ba8903 Clothing $782.62 499 0.1 82 BULK-932cc0d4
17896 Bulk Product d899875c Home & Garden $552.01 449 4.9 60 BULK-e04c6682
17897 Bulk Product 7ef184e4 Toys & Games $571.58 38 2.3 97 BULK-4ebae2b3
17898 Bulk Product c86860a1 Electronics $283.91 350 4.6 7 BULK-e2d32cf4
17899 Bulk Product 0511549e Toys & Games $815.14 3 0.1 37 BULK-2a6be549
17900 Bulk Product 7f1d016e Electronics $147.14 111 4.7 59 BULK-f0675c4c
17901 Bulk Product ba01daad Clothing $478.78 27 0.1 93 BULK-7ac0b0ac
17902 Bulk Product 4b592ecc Clothing $452.29 354 3.5 81 BULK-2b512ea6
17903 Bulk Product 44bb9c36 Clothing $843.06 144 1.5 80 BULK-2536703b
17904 Bulk Product 18115f1a Home & Garden $539.09 65 4.3 15 BULK-3ca1379e
17905 Bulk Product f23c50fa Sports & Outdoors $655.99 167 0.0 39 BULK-ed1ab129
17906 Bulk Product b9069bcd Toys & Games $609.01 488 0.8 52 BULK-8572af8d
17907 Bulk Product cb198a08 Books $657.07 235 2.6 55 BULK-91103285
17908 Bulk Product 3b88e202 Home & Garden $679.57 485 1.0 21 BULK-315c7a93
17909 Bulk Product 964ef897 Toys & Games $957.67 201 4.2 44 BULK-0f41dc75
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