Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

13 ms

Page Size

25

Current Page

647 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 647 Results Showing 16151 - 16175 of 24441

ID Name Category Price Stock Rating Reviews SKU
16710 Bulk Product a0eb27ff Books $768.41 10 1.3 67 BULK-de73f31d
16711 Bulk Product e4e60b17 Clothing $375.66 404 2.4 71 BULK-073ebb8d
16712 Bulk Product 0153d40b Toys & Games $176.99 57 2.5 53 BULK-2bc06274
16713 Bulk Product 6088f8a7 Clothing $487.69 95 4.9 82 BULK-3c5c7674
16714 Bulk Product 37c653d2 Books $208.96 466 0.4 88 BULK-ebe29fcf
16715 Bulk Product 5f7168c2 Toys & Games $804.67 320 2.2 51 BULK-b9919bd0
16716 Bulk Product ceefa1d6 Toys & Games $398.74 208 2.8 90 BULK-5cb4b450
16717 Bulk Product dc3b9cf9 Toys & Games $744.02 137 2.7 19 BULK-a577d9f8
16718 Bulk Product cdcd7f4e Electronics $488.06 156 4.5 31 BULK-fa1138af
16719 Bulk Product 58a75b03 Toys & Games $89.02 5 1.1 23 BULK-e927e852
16720 Bulk Product 8cb0e8d9 Books $904.31 156 4.0 97 BULK-642d1501
16721 Bulk Product 18767c69 Books $92.70 120 4.9 20 BULK-9cb13d7e
16722 Bulk Product 8c68d748 Clothing $722.66 131 2.5 11 BULK-cfe77cef
16723 Bulk Product 21f89338 Toys & Games $407.32 232 4.0 86 BULK-7e990ce1
16724 Bulk Product a03b8761 Electronics $977.93 274 3.7 22 BULK-8f34487e
16725 Bulk Product c056cb9b Toys & Games $963.22 222 3.8 10 BULK-4b244eae
16726 Bulk Product 2c2e328d Sports & Outdoors $981.88 169 2.6 92 BULK-e0e3f996
16727 Bulk Product 18d708b3 Sports & Outdoors $662.59 391 1.8 2 BULK-89cd8332
16728 Bulk Product f04e5bdc Home & Garden $29.65 491 2.5 77 BULK-51630771
16729 Bulk Product 08202b3d Home & Garden $861.72 317 0.4 22 BULK-26b230ce
16730 Bulk Product a1f662a6 Clothing $573.27 96 1.4 99 BULK-66f567df
16731 Bulk Product 1c24c348 Books $123.93 113 4.9 78 BULK-8d81c2d4
16732 Bulk Product 8995eaf7 Electronics $603.45 461 4.8 91 BULK-1c09badc
16733 Bulk Product c3aa591b Sports & Outdoors $989.25 422 2.1 21 BULK-d1e5832b
16734 Bulk Product 94e31284 Books $894.79 255 4.3 87 BULK-71be58c7
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