Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

29 ms

Page Size

25

Current Page

760 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 760 Results Showing 18976 - 19000 of 24441

ID Name Category Price Stock Rating Reviews SKU
19535 Bulk Product b232d7bf Sports & Outdoors $863.24 131 3.8 88 BULK-8e348377
19536 Bulk Product a878612e Sports & Outdoors $924.52 468 4.6 97 BULK-6e53a305
19537 Bulk Product 170ab1d5 Electronics $407.53 235 2.6 81 BULK-1141a76b
19538 Bulk Product 5ce52a9e Toys & Games $933.53 478 2.1 22 BULK-e21372dc
19539 Bulk Product 12e56e33 Books $899.99 253 3.9 48 BULK-33374033
19540 Bulk Product 4b846a2a Sports & Outdoors $570.10 317 4.2 57 BULK-70c4fda4
19541 Bulk Product bb068439 Clothing $284.42 39 3.0 72 BULK-c47f4d81
19542 Bulk Product e4f50758 Clothing $272.13 94 4.8 36 BULK-2f16607b
19543 Bulk Product da583e68 Home & Garden $304.88 29 2.4 92 BULK-0e0358a9
19544 Bulk Product 0d260512 Books $368.04 125 1.3 57 BULK-6739b99e
19545 Bulk Product 77a911ca Sports & Outdoors $171.08 189 3.2 56 BULK-49359ccf
19546 Bulk Product 29bb94a8 Clothing $725.22 435 2.6 25 BULK-769547f3
19547 Bulk Product 1c9ade84 Sports & Outdoors $787.92 452 3.3 73 BULK-6604bd8a
19548 Bulk Product a7af250a Home & Garden $957.22 207 3.0 74 BULK-e5948e89
19549 Bulk Product 07cbdb0b Toys & Games $957.51 416 3.7 46 BULK-a7994117
19550 Bulk Product 90bf6588 Toys & Games $852.87 154 0.7 99 BULK-2ddbdc2c
19551 Bulk Product 4d5d838c Home & Garden $86.59 268 0.6 56 BULK-6bb172d2
19552 Bulk Product 7efcb327 Sports & Outdoors $190.54 395 1.1 88 BULK-1c011ddd
19553 Bulk Product e36d9dd4 Clothing $248.91 36 1.2 56 BULK-2dbd4dc4
19554 Bulk Product d429ce87 Toys & Games $587.06 224 1.2 16 BULK-f4d56026
19555 Bulk Product 326ee781 Toys & Games $661.87 477 1.5 6 BULK-07a95c5f
19556 Bulk Product 8eca11b1 Electronics $978.81 342 3.0 42 BULK-015a2197
19557 Bulk Product 545e6822 Books $351.82 73 4.2 74 BULK-556ad1e1
19558 Bulk Product 2463f886 Home & Garden $948.62 496 2.9 38 BULK-147cbc0f
19559 Bulk Product e60daaa2 Clothing $569.32 437 1.9 81 BULK-5174e8c7
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