Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

27 ms

Page Size

25

Current Page

796 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 796 Results Showing 19876 - 19900 of 24441

ID Name Category Price Stock Rating Reviews SKU
20435 Bulk Product 1f08815e Sports & Outdoors $171.19 239 1.9 28 BULK-97888d1d
20436 Bulk Product f71d13f4 Electronics $616.32 45 1.1 64 BULK-0428ba4b
20437 Bulk Product 5e2b1c28 Toys & Games $345.82 11 1.1 97 BULK-2578044e
20438 Bulk Product a72ed1b2 Electronics $729.43 271 0.9 33 BULK-ee1091e9
20439 Bulk Product a351d92d Sports & Outdoors $715.99 356 4.6 25 BULK-16649ae9
20440 Bulk Product a99bcd7b Home & Garden $606.26 239 1.8 9 BULK-39b43fb2
20441 Bulk Product 75d6c95b Clothing $673.10 256 1.0 71 BULK-f30a03ce
20442 Bulk Product f7c5b6f7 Books $132.21 482 4.6 14 BULK-2aad7682
20443 Bulk Product 6fa042d5 Toys & Games $811.53 89 1.4 20 BULK-497d3017
20444 Bulk Product b41c03c1 Home & Garden $280.71 139 4.5 12 BULK-4f9fbd77
20445 Bulk Product f9f2a184 Sports & Outdoors $770.61 179 0.3 5 BULK-22493f94
20446 Bulk Product f7e8c385 Clothing $342.28 334 4.6 74 BULK-aeb239f5
20447 Bulk Product c6ed1e4b Toys & Games $407.70 57 4.1 9 BULK-7fe840d5
20448 Bulk Product 5be5b37e Home & Garden $197.09 196 3.7 14 BULK-2cd86c26
20449 Bulk Product ceaeb46f Toys & Games $878.94 156 1.0 54 BULK-49808e66
20450 Bulk Product 9df5db26 Toys & Games $1,000.02 411 4.5 83 BULK-6fdcace9
20451 Bulk Product a8468f77 Toys & Games $10.17 138 0.3 64 BULK-553bb0a3
20452 Bulk Product cfeb7762 Home & Garden $803.92 58 3.5 95 BULK-ef46d3c2
20453 Bulk Product 54424497 Books $73.36 346 1.4 19 BULK-142f3aff
20454 Bulk Product 15735c27 Electronics $158.55 87 1.5 62 BULK-2a176ecc
20455 Bulk Product 470c7d19 Toys & Games $932.14 295 1.0 48 BULK-4558683d
20456 Bulk Product ea3cc0c3 Clothing $946.54 90 4.6 49 BULK-5d5a54fe
20457 Bulk Product 2a5649e0 Home & Garden $303.87 157 1.7 18 BULK-41218547
20458 Bulk Product 0d9bd6ff Toys & Games $23.20 336 4.9 63 BULK-2f86d92b
20459 Bulk Product 33b10c60 Electronics $571.96 305 0.9 69 BULK-f73fe89f
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