Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

25 ms

Page Size

25

Current Page

528 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 528 Results Showing 13176 - 13200 of 24441

ID Name Category Price Stock Rating Reviews SKU
13735 Bulk Product 47fd107d Toys & Games $1,006.55 460 2.4 78 BULK-103bc76c
13736 Bulk Product 625562c6 Books $916.50 460 4.5 75 BULK-35be92e5
13737 Bulk Product 4f7da934 Home & Garden $134.61 95 0.7 46 BULK-25a7e26a
13738 Bulk Product 51588bd3 Home & Garden $1,003.09 360 2.3 6 BULK-5d4d5bab
13739 Bulk Product 7c72cfa6 Sports & Outdoors $725.73 424 3.1 19 BULK-a867c0b8
13740 Bulk Product f1a4bfcc Clothing $881.22 13 4.8 94 BULK-99927b8b
13741 Bulk Product 614909c1 Home & Garden $80.98 183 2.6 68 BULK-12213ecf
13742 Bulk Product 0748881a Toys & Games $828.11 26 4.8 21 BULK-21b25d88
13743 Bulk Product 87fa6b41 Toys & Games $815.71 354 0.5 87 BULK-46be4014
13744 Bulk Product 936930d0 Clothing $548.42 235 2.7 74 BULK-b49c3fdf
13745 Bulk Product 0f25cfc0 Home & Garden $790.96 470 1.3 1 BULK-001c6bcc
13746 Bulk Product 2b13b066 Books $295.92 120 1.1 4 BULK-46e6b2fe
13747 Bulk Product 1da0dbbf Books $877.61 115 2.1 28 BULK-68331da5
13748 Bulk Product 834680a7 Clothing $779.53 294 4.9 9 BULK-0cdfbaff
13749 Bulk Product 87944ddf Clothing $46.72 357 4.2 82 BULK-86bf61c4
13750 Bulk Product 028a0ba6 Toys & Games $203.51 470 1.0 22 BULK-30c72cf5
13751 Bulk Product db9d6531 Electronics $825.06 95 1.5 26 BULK-892d4637
13752 Bulk Product 7b274575 Home & Garden $101.40 20 1.5 36 BULK-a5e2cc43
13753 Bulk Product c16a00e5 Toys & Games $228.32 336 2.1 79 BULK-fb98b94c
13754 Bulk Product 70c584d2 Home & Garden $876.47 335 4.7 47 BULK-7b422105
13755 Bulk Product 063e11dc Books $228.25 308 2.7 7 BULK-58d85ecb
13756 Bulk Product 67139e1d Sports & Outdoors $224.38 457 2.7 25 BULK-ca882d02
13757 Bulk Product 855352b2 Electronics $883.48 130 4.3 72 BULK-80460a9d
13758 Bulk Product 7c53fbbe Home & Garden $994.29 319 4.5 43 BULK-1e812514
13759 Bulk Product 2b9fa63e Toys & Games $121.85 483 0.9 54 BULK-1eaf22dc
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