Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

16 ms

Page Size

25

Current Page

929 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 929 Results Showing 23201 - 23225 of 24441

ID Name Category Price Stock Rating Reviews SKU
23760 Bulk Product 5a4fb3b8 Toys & Games $670.33 65 2.6 63 BULK-9908a99b
23761 Bulk Product d7815779 Toys & Games $862.95 174 1.6 26 BULK-d43d31f4
23762 Bulk Product b40c6362 Electronics $873.22 13 2.2 47 BULK-56bdf4e7
23763 Bulk Product 5010e24c Sports & Outdoors $324.21 279 0.6 79 BULK-da56ad36
23764 Bulk Product 7492f370 Home & Garden $518.21 441 3.4 20 BULK-d675ad23
23765 Bulk Product 7f103067 Books $206.72 60 3.4 23 BULK-bb7e3250
23766 Bulk Product ab3f708d Clothing $817.62 277 0.9 61 BULK-c4345111
23767 Bulk Product 3a47ae99 Electronics $936.57 114 3.6 70 BULK-5f8d8ab4
23768 Bulk Product 36fb6044 Clothing $888.78 435 1.0 25 BULK-fb8f713a
23769 Bulk Product 853f79f1 Electronics $500.04 31 4.6 97 BULK-adacf196
23770 Bulk Product c3b87aa1 Clothing $759.93 285 3.6 87 BULK-01f06ef6
23771 Bulk Product 26a29c5e Books $740.28 376 0.2 21 BULK-2667a033
23772 Bulk Product a722dee5 Toys & Games $696.89 478 3.1 54 BULK-f5fb3822
23773 Bulk Product 83b3baf8 Home & Garden $481.80 203 1.0 26 BULK-4ea28ac7
23774 Bulk Product 46c6506d Sports & Outdoors $831.65 208 3.9 75 BULK-44ce1376
23775 Bulk Product d7f8b6a7 Sports & Outdoors $104.71 303 0.9 33 BULK-a2518b2a
23776 Bulk Product deb69377 Sports & Outdoors $458.41 246 0.8 37 BULK-6691faf2
23777 Bulk Product b98407a6 Toys & Games $453.68 44 1.2 61 BULK-d14183a7
23778 Bulk Product fef5b2cf Sports & Outdoors $768.14 22 3.6 49 BULK-45a3edb6
23779 Bulk Product 65ffb1b0 Clothing $431.66 136 4.6 89 BULK-faaa88d1
23780 Bulk Product 91c1f105 Toys & Games $500.65 361 2.4 53 BULK-57a7e91e
23781 Bulk Product 277d87da Electronics $415.98 392 3.8 93 BULK-81b58389
23782 Bulk Product 0a6c0fb9 Toys & Games $900.98 314 0.2 83 BULK-ea921ca8
23783 Bulk Product 95545781 Toys & Games $919.55 352 1.1 3 BULK-288a6826
23784 Bulk Product a7b7f1c9 Clothing $135.74 390 1.4 98 BULK-23fbabcd
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