Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

27 ms

Page Size

25

Current Page

927 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 927 Results Showing 23151 - 23175 of 24441

ID Name Category Price Stock Rating Reviews SKU
23710 Bulk Product f1010f3e Home & Garden $267.69 161 2.0 81 BULK-8a1c4bb9
23711 Bulk Product 4cdb7fae Toys & Games $745.80 107 2.8 54 BULK-77303aa7
23712 Bulk Product 380a0009 Sports & Outdoors $496.40 173 4.5 99 BULK-c6acdcb8
23713 Bulk Product 95cde1cb Books $545.86 410 5.0 39 BULK-8847b769
23714 Bulk Product 34ac1c94 Books $192.78 339 1.2 53 BULK-1a7fd920
23715 Bulk Product 7f4d9c9f Electronics $116.17 159 3.0 61 BULK-e1945842
23716 Bulk Product 94ce9338 Books $166.13 123 0.1 69 BULK-28f92afc
23717 Bulk Product e33347a1 Clothing $822.53 95 2.3 84 BULK-36eff8b6
23718 Bulk Product 96863541 Home & Garden $763.44 391 1.8 11 BULK-632934da
23719 Bulk Product f68e44cd Home & Garden $366.58 237 4.7 52 BULK-7454a0c6
23720 Bulk Product a4140096 Toys & Games $230.41 445 3.4 75 BULK-bd34f070
23721 Bulk Product 6c85a099 Home & Garden $586.03 73 2.4 99 BULK-d6011e3f
23722 Bulk Product 4bed1d9a Sports & Outdoors $406.97 418 2.9 69 BULK-1ae9397a
23723 Bulk Product da847abf Electronics $813.66 183 4.8 25 BULK-dc3b4b5c
23724 Bulk Product 02e01baa Electronics $576.22 468 1.1 14 BULK-c90d473f
23725 Bulk Product af5494ab Home & Garden $878.51 476 0.8 97 BULK-69d1196e
23726 Bulk Product da38341b Home & Garden $439.18 20 4.7 53 BULK-6cdd9970
23727 Bulk Product 366db0be Books $559.88 145 3.9 32 BULK-6db0c19b
23728 Bulk Product f4880e53 Electronics $468.54 161 1.6 98 BULK-ea10a1de
23729 Bulk Product 9d0f58ba Sports & Outdoors $282.80 398 0.4 78 BULK-e06b4a18
23730 Bulk Product a3add003 Electronics $29.03 309 3.4 23 BULK-fe323cf2
23731 Bulk Product b9f98892 Toys & Games $550.73 478 3.5 60 BULK-96bfa6da
23732 Bulk Product 674ac232 Electronics $154.04 168 2.0 98 BULK-55f648a0
23733 Bulk Product 7039d347 Toys & Games $852.93 309 1.5 20 BULK-c43e626c
23734 Bulk Product 3be93715 Electronics $317.29 414 3.0 89 BULK-1842e8ef
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