Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

31 ms

Page Size

25

Current Page

451 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 451 Results Showing 11251 - 11275 of 24441

ID Name Category Price Stock Rating Reviews SKU
11810 Bulk Product 38eb1bde Home & Garden $871.02 327 0.7 81 BULK-96650738
11811 Bulk Product 71f8dfa4 Clothing $854.19 235 2.9 41 BULK-cb6ac060
11812 Bulk Product cfb3b4c3 Toys & Games $983.21 55 0.6 76 BULK-a8387de5
11813 Bulk Product 07985605 Sports & Outdoors $580.62 131 3.7 71 BULK-f8905969
11814 Bulk Product 103a8e51 Toys & Games $1,006.42 497 3.1 8 BULK-a48880dd
11815 Bulk Product cd758c33 Toys & Games $369.23 416 4.8 60 BULK-fbf48976
11816 Bulk Product af804d8b Toys & Games $354.73 460 0.0 40 BULK-b34512d9
11817 Bulk Product 622aab2b Books $460.52 265 2.0 37 BULK-70fcf395
11818 Bulk Product d4353c44 Home & Garden $450.51 266 4.4 86 BULK-531ae73c
11819 Bulk Product 311c0976 Toys & Games $487.01 288 4.9 13 BULK-4e52efce
11820 Bulk Product 0e9ff3fa Books $486.11 158 1.3 82 BULK-c57d075e
11821 Bulk Product 295e03e6 Toys & Games $150.05 454 0.1 25 BULK-5be87f77
11822 Bulk Product 16a4d230 Toys & Games $841.71 287 3.4 31 BULK-86c22294
11823 Bulk Product 26342d59 Home & Garden $630.11 158 0.5 29 BULK-736a0be1
11824 Bulk Product 741d85df Toys & Games $310.61 419 1.1 35 BULK-b0526723
11825 Bulk Product 6a26491b Home & Garden $606.20 316 2.7 60 BULK-2fc0de4b
11826 Bulk Product 116d31e5 Books $737.30 73 2.3 34 BULK-946114a1
11827 Bulk Product ec866f1c Electronics $857.46 293 3.5 97 BULK-fbbd8e3d
11828 Bulk Product 2e02bceb Electronics $266.41 494 0.3 19 BULK-aea2ffa8
11829 Bulk Product eafa26a7 Sports & Outdoors $358.00 6 4.4 7 BULK-89d89fe5
11830 Bulk Product 5de7a6e8 Sports & Outdoors $476.55 229 1.6 46 BULK-2f30ae99
11831 Bulk Product 09807e9f Toys & Games $607.57 409 2.4 88 BULK-6a9ecc89
11832 Bulk Product ffad1879 Home & Garden $539.66 476 3.9 15 BULK-9491a2ba
11833 Bulk Product 7915fe94 Sports & Outdoors $693.37 70 2.5 28 BULK-8155c8f5
11834 Bulk Product efc8ad3e Sports & Outdoors $506.23 29 4.0 6 BULK-722fc0b0
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