Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

24 ms

Page Size

25

Current Page

480 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 480 Results Showing 11976 - 12000 of 24441

ID Name Category Price Stock Rating Reviews SKU
12535 Bulk Product f12e174a Electronics $702.19 252 2.7 32 BULK-4328e7af
12536 Bulk Product e9c3ff63 Home & Garden $534.73 79 3.8 45 BULK-7970a48c
12537 Bulk Product 914dc214 Home & Garden $986.77 50 0.7 33 BULK-6cdd8286
12538 Bulk Product 492a692d Home & Garden $106.00 42 3.4 16 BULK-908baa02
12539 Bulk Product 600e3b82 Sports & Outdoors $268.66 155 4.4 40 BULK-d0affe88
12540 Bulk Product 41e4968d Books $540.87 389 0.1 5 BULK-ccefee38
12541 Bulk Product b80ab643 Electronics $594.03 144 4.5 89 BULK-2721a945
12542 Bulk Product 6fd67d2e Electronics $932.16 148 3.7 22 BULK-fea4babd
12543 Bulk Product cbb911fa Sports & Outdoors $827.49 9 2.6 58 BULK-4ce97d4b
12544 Bulk Product 66c3ff26 Electronics $798.91 444 3.3 46 BULK-bedfc37b
12545 Bulk Product 9b221c59 Home & Garden $967.56 234 1.6 54 BULK-00cb5758
12546 Bulk Product 393790db Home & Garden $549.35 343 4.4 34 BULK-ac00ec4c
12547 Bulk Product c2711664 Home & Garden $395.65 94 0.4 77 BULK-21407ac3
12548 Bulk Product 709127de Books $868.94 352 4.5 47 BULK-919f8523
12549 Bulk Product 135f71a8 Toys & Games $533.26 239 1.5 73 BULK-28bb69c9
12550 Bulk Product 86f51a0d Toys & Games $463.71 19 0.6 87 BULK-05c6f707
12551 Bulk Product de2201e3 Electronics $989.21 398 3.6 64 BULK-ebb50b81
12552 Bulk Product a1f72a5d Toys & Games $512.95 160 4.9 47 BULK-28c19347
12553 Bulk Product 3896e096 Toys & Games $16.99 490 4.8 19 BULK-8889b394
12554 Bulk Product b571a5af Toys & Games $964.93 418 0.9 2 BULK-e7a13064
12555 Bulk Product c9fd5bfb Electronics $541.35 318 3.1 10 BULK-6cc5ffb1
12556 Bulk Product 912690ed Clothing $328.07 86 1.4 70 BULK-48686b90
12557 Bulk Product 033daefb Toys & Games $736.93 493 0.2 52 BULK-7c03fc1c
12558 Bulk Product d145ee9c Home & Garden $676.26 319 0.6 29 BULK-d88c5b67
12559 Bulk Product 7b96d301 Books $466.96 450 0.4 14 BULK-1a51fae9
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