Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

21 ms

Page Size

50

Current Page

450 / 489

Total Records

24441

Items per page: 25 50 100 200

Page 450 Results Showing 22451 - 22500 of 24441

ID Name Category Price Stock Rating Reviews SKU
23010 Bulk Product b9f0c648 Electronics $318.86 416 1.5 22 BULK-47bcab62
23011 Bulk Product 08b8eb46 Books $420.49 248 3.0 51 BULK-647f1b55
23012 Bulk Product c978eee4 Books $597.56 489 4.3 1 BULK-bc2a9d32
23013 Bulk Product f81dcc36 Electronics $60.04 474 0.5 75 BULK-80b9a8a9
23014 Bulk Product dfe54738 Electronics $133.55 85 1.0 94 BULK-5f91ad57
23015 Bulk Product 1da9af08 Electronics $138.14 180 4.9 61 BULK-0bd0d471
23016 Bulk Product e4b0baa3 Toys & Games $12.36 175 1.8 62 BULK-dc8d2292
23017 Bulk Product abf20210 Clothing $732.26 438 4.7 26 BULK-8639666d
23018 Bulk Product db445af2 Home & Garden $967.79 165 3.3 17 BULK-9c7a4bf5
23019 Bulk Product dfe91e1d Home & Garden $734.81 213 3.3 85 BULK-8e26cca3
23020 Bulk Product 17e9b5d4 Books $705.90 205 5.0 78 BULK-f9c1d03a
23021 Bulk Product 279a9526 Home & Garden $129.19 375 4.3 81 BULK-b43ef217
23022 Bulk Product 7f6ddd44 Toys & Games $727.78 223 4.0 70 BULK-09dae538
23023 Bulk Product 047afea0 Books $273.63 140 1.4 71 BULK-d2c543b0
23024 Bulk Product 3db13b1f Clothing $721.88 443 3.2 12 BULK-5e9e18bd
23025 Bulk Product 89b1025a Books $41.17 56 3.2 22 BULK-6d74ab01
23026 Bulk Product 80478a6d Books $597.30 267 3.5 85 BULK-76902b64
23027 Bulk Product 33f36bed Books $1,000.88 18 2.8 0 BULK-07664b4e
23028 Bulk Product 183fb346 Clothing $378.46 279 1.9 94 BULK-59ccd5a7
23029 Bulk Product 43f6485b Clothing $293.46 87 4.1 43 BULK-4069cf37
23030 Bulk Product 59664404 Electronics $246.86 422 3.5 29 BULK-bf7b03b2
23031 Bulk Product 65c6d6bc Books $463.85 261 0.7 63 BULK-41db9aaf
23032 Bulk Product 2c10cca3 Books $170.55 486 1.9 60 BULK-2f47ba1a
23033 Bulk Product 8f829a52 Books $257.28 335 4.2 67 BULK-c5e14882
23034 Bulk Product e8069411 Sports & Outdoors $689.34 283 4.1 32 BULK-6bc65795
23035 Bulk Product c2f98a6f Electronics $728.13 66 2.1 33 BULK-af5bf0e2
23036 Bulk Product 59b5edc0 Home & Garden $295.44 326 1.9 64 BULK-41c394cd
23037 Bulk Product 4aa6bc5f Clothing $785.76 110 2.1 37 BULK-20130544
23038 Bulk Product 2aad1ebd Home & Garden $257.58 141 2.2 61 BULK-e9704886
23039 Bulk Product 366e499a Electronics $413.96 61 5.0 52 BULK-1c1d91d7
23040 Bulk Product 0aabccec Books $420.39 197 4.0 13 BULK-c444cc66
23041 Bulk Product 71ae5cb9 Electronics $877.04 277 4.7 91 BULK-7e89d0eb
23042 Bulk Product 0abf43ab Toys & Games $164.73 487 3.2 30 BULK-87f455ce
23043 Bulk Product e8bb119d Home & Garden $178.85 119 1.7 50 BULK-f40120e7
23044 Bulk Product c8258812 Toys & Games $556.40 57 2.3 56 BULK-f28d6658
23045 Bulk Product 23219a84 Clothing $647.67 304 4.2 79 BULK-5ad31afb
23046 Bulk Product 9466051a Home & Garden $326.39 32 3.2 76 BULK-2e89b128
23047 Bulk Product e78d79f0 Books $797.18 170 4.0 13 BULK-dce6975e
23048 Bulk Product 3dd53898 Toys & Games $249.53 78 1.4 39 BULK-fbdb8013
23049 Bulk Product 23ccc14a Electronics $146.14 364 0.3 49 BULK-9bfd078c
23050 Bulk Product ce6b0707 Books $496.61 273 0.1 2 BULK-a876bf00
23051 Bulk Product a2692ba7 Books $883.65 340 0.0 86 BULK-ba3c19f5
23052 Bulk Product b1f812cc Clothing $291.84 293 0.3 34 BULK-064f6b44
23053 Bulk Product ed874e29 Clothing $494.36 102 2.1 71 BULK-d6b28a06
23054 Bulk Product 8bd4cda4 Books $57.93 46 0.6 35 BULK-1d7fb608
23055 Bulk Product ece434b0 Electronics $517.26 379 3.8 38 BULK-8e6e666f
23056 Bulk Product c7163fc5 Clothing $474.82 245 1.0 82 BULK-7a5bbc74
23057 Bulk Product 63e47941 Books $530.40 145 4.7 43 BULK-8e80230f
23058 Bulk Product 8a8314b9 Home & Garden $727.31 86 1.8 58 BULK-18a752b4
23059 Bulk Product ade0706b Sports & Outdoors $833.43 195 0.2 84 BULK-e2c484ca
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