Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

14 ms

Page Size

25

Current Page

801 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 801 Results Showing 20001 - 20025 of 24441

ID Name Category Price Stock Rating Reviews SKU
20560 Bulk Product 8d4bd6e2 Clothing $80.51 447 0.4 65 BULK-65c8bafc
20561 Bulk Product 5804cbce Clothing $392.30 247 3.6 47 BULK-4af7fd0d
20562 Bulk Product 71fae38b Electronics $873.01 106 0.4 96 BULK-1ce73cf9
20563 Bulk Product 409e3181 Sports & Outdoors $405.50 389 0.6 49 BULK-dc2eb302
20564 Bulk Product 52a8d4f6 Home & Garden $115.66 126 4.0 33 BULK-1c5cfe29
20565 Bulk Product c193c779 Toys & Games $908.28 435 4.9 38 BULK-af5a651f
20566 Bulk Product 40f17e9c Clothing $70.88 281 2.9 30 BULK-2a46c82d
20567 Bulk Product 128551bc Electronics $54.40 305 0.2 14 BULK-ad64bd71
20568 Bulk Product 6631593e Sports & Outdoors $219.76 336 2.1 33 BULK-f5cfd747
20569 Bulk Product 834dd5ff Clothing $120.59 127 4.3 31 BULK-6d5eb73a
20570 Bulk Product 329f7bd4 Home & Garden $386.73 328 4.9 98 BULK-7fed6b0d
20571 Bulk Product 2e392d2b Sports & Outdoors $733.44 246 0.7 34 BULK-95130563
20572 Bulk Product ed229c7b Toys & Games $220.05 165 2.7 23 BULK-804ca855
20573 Bulk Product 406cebc5 Toys & Games $853.72 82 0.4 19 BULK-d9bc726c
20574 Bulk Product e454e17c Home & Garden $883.21 260 2.6 38 BULK-d367580d
20575 Bulk Product 657a46d1 Home & Garden $964.16 336 2.7 51 BULK-dfec22c3
20576 Bulk Product 038ea83b Electronics $11.44 245 1.6 81 BULK-92df9309
20577 Bulk Product a5492db6 Electronics $959.88 291 4.0 68 BULK-36a3d933
20578 Bulk Product 332a3a08 Clothing $797.26 376 3.3 96 BULK-2450c452
20579 Bulk Product 69f7d27a Sports & Outdoors $770.72 129 0.6 76 BULK-ff2af580
20580 Bulk Product 7b5d469a Books $55.56 197 3.3 29 BULK-ae07bcab
20581 Bulk Product c3eced66 Toys & Games $177.84 413 4.2 56 BULK-3a29f2af
20582 Bulk Product e505420d Home & Garden $550.57 181 0.7 33 BULK-d545a1a6
20583 Bulk Product 1754e6a6 Toys & Games $982.47 122 3.7 3 BULK-a4ea145a
20584 Bulk Product d44ce4d6 Toys & Games $163.07 321 1.9 10 BULK-d450510e
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