Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

84 ms

Page Size

25

Current Page

833 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 833 Results Showing 20801 - 20825 of 24441

ID Name Category Price Stock Rating Reviews SKU
21360 Bulk Product 834935e1 Home & Garden $687.00 337 0.8 57 BULK-dfea1553
21361 Bulk Product a0403240 Home & Garden $204.86 459 3.8 63 BULK-d5e478b5
21362 Bulk Product faa84606 Home & Garden $440.04 260 0.4 70 BULK-09e2f69d
21363 Bulk Product 330d6a00 Electronics $117.60 66 3.2 20 BULK-7a5560c0
21364 Bulk Product 23875741 Toys & Games $628.41 395 3.8 25 BULK-4cd3b345
21365 Bulk Product 19009c2e Electronics $471.00 309 2.4 59 BULK-172bd53f
21366 Bulk Product 67fe6f2d Sports & Outdoors $447.01 128 2.2 52 BULK-9401ac45
21367 Bulk Product 6b3a46a4 Toys & Games $460.19 68 4.0 92 BULK-7e0795f8
21368 Bulk Product acea3bde Toys & Games $65.80 259 2.0 77 BULK-23b17b85
21369 Bulk Product 0182c866 Electronics $957.47 153 0.1 1 BULK-5494b43e
21370 Bulk Product 3aa78a02 Sports & Outdoors $803.14 73 1.4 95 BULK-d9d49f4e
21371 Bulk Product 79127a6d Clothing $633.18 30 2.6 86 BULK-d6e2e3a0
21372 Bulk Product 6532481b Electronics $677.78 369 3.1 38 BULK-9471ed39
21373 Bulk Product aba51b5a Home & Garden $617.54 218 3.8 3 BULK-db30761c
21374 Bulk Product e609bb3e Home & Garden $293.41 278 3.7 26 BULK-7653a791
21375 Bulk Product 534ea730 Toys & Games $952.82 54 3.1 78 BULK-cd9f24eb
21376 Bulk Product c0bb4a4b Books $845.97 2 3.8 68 BULK-f49944fc
21377 Bulk Product f89f1088 Toys & Games $809.42 443 2.7 73 BULK-8b0ec854
21378 Bulk Product 7cc4f8ad Clothing $184.74 131 4.5 87 BULK-b649b2a8
21379 Bulk Product 0c727942 Clothing $335.72 133 4.6 89 BULK-9f3c256e
21380 Bulk Product d1b9a6f7 Toys & Games $827.13 469 3.9 22 BULK-3aeab10f
21381 Bulk Product 0ed7c9bf Electronics $32.65 433 2.2 27 BULK-0c0d9792
21382 Bulk Product 6e1c9753 Sports & Outdoors $130.00 248 4.4 56 BULK-e6468a8a
21383 Bulk Product 9f37a5ad Electronics $817.09 138 3.9 30 BULK-79579c11
21384 Bulk Product 1f6f8080 Sports & Outdoors $441.59 325 3.8 7 BULK-bac5a3a2
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