Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

28 ms

Page Size

25

Current Page

751 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 751 Results Showing 18751 - 18775 of 24441

ID Name Category Price Stock Rating Reviews SKU
19310 Bulk Product 1e106800 Toys & Games $875.75 291 1.3 87 BULK-7b63f045
19311 Bulk Product 2982ae78 Toys & Games $69.58 302 0.7 29 BULK-d89f3933
19312 Bulk Product 70bdfab3 Electronics $848.00 388 4.7 88 BULK-28de7827
19313 Bulk Product f64ae537 Electronics $24.47 210 1.6 47 BULK-07d9cb73
19314 Bulk Product 7d0d8ce1 Toys & Games $417.85 436 4.1 45 BULK-bfb13002
19315 Bulk Product a7576fca Home & Garden $96.75 317 1.6 11 BULK-1b131329
19316 Bulk Product 3effc9bf Clothing $912.04 89 4.2 79 BULK-ab07fd24
19317 Bulk Product 41c8a2e0 Books $96.21 323 3.6 89 BULK-968b3e6b
19318 Bulk Product 54aacf4b Books $126.22 128 2.1 5 BULK-46bcf1da
19319 Bulk Product d53c2755 Toys & Games $218.07 11 3.0 30 BULK-aab3e2cc
19320 Bulk Product 40ee2bea Toys & Games $98.28 43 4.3 23 BULK-1e522f22
19321 Bulk Product 9ffd640c Home & Garden $406.23 211 0.4 62 BULK-6735da0a
19322 Bulk Product 5e861eeb Electronics $136.04 23 3.8 65 BULK-1a2be0b9
19323 Bulk Product 114e07bf Electronics $166.57 377 3.5 93 BULK-7d146d2c
19324 Bulk Product 5ae88021 Home & Garden $474.17 286 1.5 40 BULK-f7ba1ad1
19325 Bulk Product 47ca47b4 Books $856.91 227 1.4 15 BULK-6653fee5
19326 Bulk Product dd0520c3 Books $251.35 67 4.6 34 BULK-f3cbf2fd
19327 Bulk Product 50d97b9e Clothing $514.26 489 2.5 45 BULK-96b6cd4b
19328 Bulk Product 5b79daab Toys & Games $637.83 489 2.9 13 BULK-3617234a
19329 Bulk Product 5da0a2c7 Toys & Games $362.56 362 3.1 0 BULK-1697fb56
19330 Bulk Product ebfa47d1 Electronics $492.37 131 0.1 25 BULK-ef8836ed
19331 Bulk Product d1852358 Books $262.54 394 1.0 28 BULK-bf48a542
19332 Bulk Product 038574b8 Sports & Outdoors $933.80 43 4.7 40 BULK-6a4c749f
19333 Bulk Product 32c77881 Sports & Outdoors $185.91 63 2.5 77 BULK-7f499c03
19334 Bulk Product e3174598 Books $458.47 145 3.8 77 BULK-b874d6a7
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