Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

12 ms

Page Size

25

Current Page

765 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 765 Results Showing 19101 - 19125 of 24441

ID Name Category Price Stock Rating Reviews SKU
19660 Bulk Product 7ffd5acf Clothing $100.22 308 2.7 47 BULK-fe0379f4
19661 Bulk Product 1e067945 Books $117.96 16 4.9 10 BULK-ff516d48
19662 Bulk Product 0b41f1b6 Clothing $703.37 86 4.1 21 BULK-7be16e25
19663 Bulk Product 25c0cfff Clothing $147.16 121 1.0 30 BULK-dd238ac2
19664 Bulk Product ba931484 Sports & Outdoors $757.85 24 1.1 4 BULK-740220cc
19665 Bulk Product e11d7b00 Sports & Outdoors $283.46 453 4.3 95 BULK-6c1cb091
19666 Bulk Product cfcbc6f0 Electronics $16.02 21 4.1 11 BULK-706de316
19667 Bulk Product 1fcc2c36 Toys & Games $229.40 198 0.0 60 BULK-122d36dd
19668 Bulk Product 554c2758 Electronics $796.07 485 1.2 44 BULK-fbc7d9e1
19669 Bulk Product bdee0a81 Books $738.60 128 3.3 2 BULK-7ea1955b
19670 Bulk Product 64c666d3 Books $602.23 103 1.7 36 BULK-02de3bb1
19671 Bulk Product ed60b842 Electronics $734.77 297 2.8 4 BULK-b6c2777c
19672 Bulk Product fb27f436 Electronics $447.30 276 2.1 82 BULK-ec197d52
19673 Bulk Product 5bbdcf13 Toys & Games $945.74 338 2.6 48 BULK-458c9628
19674 Bulk Product a680f17e Sports & Outdoors $940.49 20 1.3 32 BULK-4e8924ef
19675 Bulk Product dd11b652 Clothing $343.17 241 4.2 61 BULK-40ac071b
19676 Bulk Product a00196be Toys & Games $927.67 144 0.7 93 BULK-db49af8d
19677 Bulk Product 74746dc6 Toys & Games $877.45 142 2.7 2 BULK-3d2ea8df
19678 Bulk Product 1d32f75b Electronics $886.72 310 1.7 60 BULK-0a9eef63
19679 Bulk Product 25a0ecc0 Clothing $957.50 422 0.5 29 BULK-7b2d93fe
19680 Bulk Product 60ff3b4a Electronics $578.89 416 2.9 62 BULK-a981d195
19681 Bulk Product d557a001 Sports & Outdoors $924.61 399 1.3 71 BULK-6532dff3
19682 Bulk Product 8b46d64d Home & Garden $741.35 263 1.6 59 BULK-a814e291
19683 Bulk Product e063fe7c Books $97.85 395 3.3 99 BULK-bc929605
19684 Bulk Product d284210e Electronics $909.20 235 0.6 74 BULK-85a933ba
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