Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

21 ms

Page Size

25

Current Page

263 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 263 Results Showing 6551 - 6575 of 24441

ID Name Category Price Stock Rating Reviews SKU
7110 Bulk Product 39319734 Sports & Outdoors $122.67 85 1.1 44 BULK-c784156d
7111 Bulk Product c6844cd7 Toys & Games $380.34 277 3.1 81 BULK-e57d39e3
7112 Bulk Product 7a7b187f Clothing $618.20 157 0.3 71 BULK-073840a2
7113 Bulk Product 4469683e Electronics $724.61 160 3.3 6 BULK-70a836f1
7114 Bulk Product 418d43df Books $191.73 21 0.9 32 BULK-57c5d6af
7115 Bulk Product b746a64b Sports & Outdoors $367.84 315 0.2 70 BULK-37bf7ee1
7116 Bulk Product 6caefd93 Sports & Outdoors $227.87 193 4.4 54 BULK-32318e77
7117 Bulk Product e1299839 Toys & Games $275.59 48 1.9 67 BULK-56f1c143
7118 Bulk Product 1e8a3f20 Clothing $176.64 338 0.3 70 BULK-8d8b3f41
7119 Bulk Product 4b802cbc Books $121.49 104 1.0 50 BULK-3602f762
7120 Bulk Product d9d2fed7 Books $424.29 340 0.1 41 BULK-c9c63d0e
7121 Bulk Product 139fd61c Toys & Games $68.62 213 4.0 44 BULK-4f299d80
7122 Bulk Product 64e072a2 Home & Garden $452.46 163 4.4 32 BULK-6c5cbec2
7123 Bulk Product f0ec7eef Toys & Games $391.83 190 0.7 31 BULK-82d0384a
7124 Bulk Product 8cccc7c5 Home & Garden $643.34 318 4.8 92 BULK-3389985b
7125 Bulk Product 2d283579 Clothing $964.34 54 4.4 43 BULK-ab8e262e
7126 Bulk Product b06fb0bf Clothing $472.77 478 1.5 0 BULK-cc9d2a00
7127 Bulk Product 2bf6ae73 Clothing $387.43 435 2.2 22 BULK-fcc117e0
7128 Bulk Product 8e94fb4a Toys & Games $527.49 117 2.2 50 BULK-985ba14c
7129 Bulk Product 63650aa9 Toys & Games $16.55 48 3.2 34 BULK-78369598
7130 Bulk Product 3681c03b Sports & Outdoors $347.02 154 4.6 15 BULK-8762bbc3
7131 Bulk Product 24fdf7ce Electronics $793.63 168 3.8 79 BULK-3c4f58c5
7132 Bulk Product 2f33d2c4 Sports & Outdoors $151.75 305 2.1 54 BULK-dab4f932
7133 Bulk Product b4e03bfe Home & Garden $499.07 354 1.3 76 BULK-3914d99e
7134 Bulk Product 719a01e8 Toys & Games $952.43 440 0.8 29 BULK-e74d60ba
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