Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

20 ms

Page Size

25

Current Page

887 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 887 Results Showing 22151 - 22175 of 24441

ID Name Category Price Stock Rating Reviews SKU
22710 Bulk Product 211fa2f0 Clothing $272.81 27 0.9 22 BULK-eb866db2
22711 Bulk Product af3608bb Electronics $467.71 60 0.3 82 BULK-dc426775
22712 Bulk Product 30a7ebeb Clothing $891.70 76 4.9 35 BULK-e3171daa
22713 Bulk Product d2e22e35 Electronics $535.32 53 0.6 97 BULK-76bebfc5
22714 Bulk Product df68c3fe Electronics $591.91 434 4.8 99 BULK-67c4b9ea
22715 Bulk Product 202c6b10 Sports & Outdoors $323.91 271 3.1 59 BULK-24e3149b
22716 Bulk Product 33974285 Books $363.40 118 1.7 83 BULK-fbb47a60
22717 Bulk Product 0356d0fb Toys & Games $642.07 472 1.8 45 BULK-c64fd6a4
22718 Bulk Product 24c47225 Books $605.11 21 1.4 90 BULK-ea4a3403
22719 Bulk Product 88cb2bb3 Electronics $567.94 345 1.6 61 BULK-5b2c8a85
22720 Bulk Product 71d4a656 Home & Garden $582.89 76 2.6 24 BULK-792311a9
22721 Bulk Product 66ca2284 Books $784.77 281 3.1 26 BULK-c006cdad
22722 Bulk Product 7333e4ef Home & Garden $724.86 277 0.5 94 BULK-81c84ac3
22723 Bulk Product f499b21e Home & Garden $45.98 358 2.2 49 BULK-c9c47817
22724 Bulk Product 567175f8 Home & Garden $291.40 9 4.0 27 BULK-fe5704ce
22725 Bulk Product 37a00217 Books $52.29 382 4.3 96 BULK-adf239cc
22726 Bulk Product 6226f5ed Home & Garden $592.48 165 0.2 29 BULK-129a3a39
22727 Bulk Product 374c1536 Clothing $707.58 175 4.1 81 BULK-d58b6179
22728 Bulk Product 427abf5e Books $384.92 368 4.1 78 BULK-8806f90a
22729 Bulk Product 4461e889 Home & Garden $86.55 169 4.9 52 BULK-ab72d919
22730 Bulk Product 32a4540d Toys & Games $932.77 209 2.3 97 BULK-adb464bd
22731 Bulk Product 1ecfdae4 Toys & Games $916.62 486 1.2 32 BULK-9ae27d8a
22732 Bulk Product 2208d0a7 Books $983.45 159 3.8 43 BULK-c8b09b15
22733 Bulk Product 80d641e7 Electronics $59.53 119 1.4 66 BULK-ab66f4c0
22734 Bulk Product d620d982 Clothing $398.38 306 4.5 23 BULK-0a9750bb
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