Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

24 ms

Page Size

25

Current Page

663 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 663 Results Showing 16551 - 16575 of 24441

ID Name Category Price Stock Rating Reviews SKU
17110 Bulk Product 2f13e6dc Home & Garden $91.51 425 3.0 99 BULK-521fbc3a
17111 Bulk Product 9aed46da Toys & Games $432.67 427 0.3 46 BULK-c1106843
17112 Bulk Product 1d40f293 Home & Garden $454.82 347 3.8 42 BULK-83b0f061
17113 Bulk Product 21a05dde Home & Garden $194.89 14 1.2 70 BULK-ba7080e6
17114 Bulk Product 81a5d4a7 Sports & Outdoors $475.63 439 1.4 22 BULK-8e1fc669
17115 Bulk Product 38e6371d Home & Garden $910.79 493 4.3 50 BULK-8da13a3d
17116 Bulk Product 9466d355 Books $113.44 213 1.2 58 BULK-40cf2a8c
17117 Bulk Product 99a701b7 Books $767.32 467 2.3 51 BULK-c26301f9
17118 Bulk Product d2dd93c3 Clothing $743.10 462 1.3 0 BULK-06bca4bb
17119 Bulk Product 006f3e70 Books $333.42 28 0.2 17 BULK-2a7a8763
17120 Bulk Product 97bad57c Home & Garden $655.05 245 3.5 69 BULK-29b5e3c1
17121 Bulk Product 33ceed11 Sports & Outdoors $76.73 72 2.6 38 BULK-d7f50018
17122 Bulk Product 4e59b22a Home & Garden $864.87 227 2.8 51 BULK-cb86acf4
17123 Bulk Product 2576d7c2 Sports & Outdoors $247.21 77 1.4 58 BULK-193cace8
17124 Bulk Product 6a29c828 Electronics $916.35 386 3.6 48 BULK-47b08560
17125 Bulk Product a59abb71 Books $769.90 35 3.3 87 BULK-e1f3d972
17126 Bulk Product 1f66b712 Home & Garden $640.51 431 2.3 16 BULK-109328d3
17127 Bulk Product 86678cff Home & Garden $738.22 458 1.8 23 BULK-805b2a5a
17128 Bulk Product df498c9c Clothing $858.99 379 0.6 70 BULK-6a7c9413
17129 Bulk Product 70546d35 Clothing $434.26 90 4.8 99 BULK-46af0c7e
17130 Bulk Product ced59156 Electronics $379.56 276 3.0 27 BULK-a327ac1d
17131 Bulk Product 7f52f74c Books $661.93 456 5.0 6 BULK-57fa5479
17132 Bulk Product 5461f564 Books $802.83 380 0.1 85 BULK-12f09fb4
17133 Bulk Product 667376a8 Home & Garden $101.14 479 2.9 89 BULK-796de977
17134 Bulk Product c5ac24af Electronics $478.26 91 3.8 76 BULK-ccaac6b9
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