Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

23 ms

Page Size

50

Current Page

410 / 489

Total Records

24441

Items per page: 25 50 100 200

Page 410 Results Showing 20451 - 20500 of 24441

ID Name Category Price Stock Rating Reviews SKU
21010 Bulk Product 64e0cac4 Clothing $828.97 429 2.6 5 BULK-2b5734af
21011 Bulk Product 41bd9d91 Toys & Games $703.30 406 3.5 18 BULK-8c689ed1
21012 Bulk Product 6b2e46bd Electronics $143.18 99 2.9 72 BULK-f55f1378
21013 Bulk Product fa6ea93a Home & Garden $711.72 139 3.0 65 BULK-2134f972
21014 Bulk Product c8054548 Clothing $60.43 171 1.3 42 BULK-5bfb822a
21015 Bulk Product d1f65259 Home & Garden $292.31 470 2.9 8 BULK-cccd6443
21016 Bulk Product 1a2e5926 Electronics $544.02 101 4.0 90 BULK-f70201e9
21017 Bulk Product c1e4c7c0 Home & Garden $58.70 447 2.0 39 BULK-bd3cee52
21018 Bulk Product 30c49f41 Clothing $1,009.03 377 0.4 75 BULK-375b5ca2
21019 Bulk Product b4921e17 Home & Garden $690.15 380 2.3 32 BULK-648e0769
21020 Bulk Product 03fbd7b6 Electronics $546.45 189 0.0 31 BULK-e295f0fb
21021 Bulk Product 2bcef65b Toys & Games $978.44 410 0.6 35 BULK-06da5996
21022 Bulk Product 5f88bb10 Sports & Outdoors $190.65 362 3.5 84 BULK-8307595c
21023 Bulk Product c9cf6a10 Clothing $292.33 69 3.8 25 BULK-903c65bf
21024 Bulk Product 2aedfe38 Sports & Outdoors $615.30 264 2.9 66 BULK-e991741f
21025 Bulk Product 0bfc2199 Home & Garden $979.18 124 2.0 78 BULK-3a2b035b
21026 Bulk Product bf636d34 Sports & Outdoors $925.92 387 0.9 79 BULK-db226dfb
21027 Bulk Product 6f89947f Books $915.02 375 3.9 99 BULK-f93c0844
21028 Bulk Product a80f2a55 Books $652.26 26 1.6 85 BULK-75a96c03
21029 Bulk Product 40b2982e Sports & Outdoors $490.23 129 2.3 86 BULK-c1cea1fb
21030 Bulk Product d6513196 Clothing $456.85 345 4.0 43 BULK-14e4b533
21031 Bulk Product 8c148274 Electronics $93.40 164 3.4 50 BULK-eeca860b
21032 Bulk Product 2c7c6bf9 Books $646.70 453 4.2 99 BULK-a951093d
21033 Bulk Product 33d3518c Clothing $947.92 426 2.1 49 BULK-be8e9fe0
21034 Bulk Product 2f3467af Sports & Outdoors $602.24 486 2.8 71 BULK-b37fffde
21035 Bulk Product 1810200b Electronics $579.68 93 0.7 17 BULK-ad8a98a5
21036 Bulk Product b7430473 Sports & Outdoors $940.77 107 4.2 23 BULK-30308624
21037 Bulk Product caf43be1 Toys & Games $300.98 106 1.9 8 BULK-8316675e
21038 Bulk Product 72a1c191 Clothing $436.95 10 3.4 65 BULK-5611659b
21039 Bulk Product cf86a9cb Books $913.10 111 3.6 5 BULK-9c3fa3c0
21040 Bulk Product 5003ba90 Books $293.73 493 2.9 93 BULK-df29ca25
21041 Bulk Product a2fcc309 Sports & Outdoors $81.62 334 0.3 65 BULK-e900e5bc
21042 Bulk Product e3b0be98 Toys & Games $870.65 378 4.3 1 BULK-416e7bf4
21043 Bulk Product ed02cabb Home & Garden $650.75 423 0.5 9 BULK-3c85335c
21044 Bulk Product d17eae45 Toys & Games $837.60 50 3.3 82 BULK-fa55ac0e
21045 Bulk Product c202f418 Books $410.50 76 2.4 28 BULK-d34c659e
21046 Bulk Product eeb5a8ee Toys & Games $240.93 124 0.4 26 BULK-479f5e9b
21047 Bulk Product 91e38a76 Clothing $341.60 198 2.8 17 BULK-35a4643f
21048 Bulk Product 143e5516 Sports & Outdoors $652.42 222 1.5 38 BULK-7ed292cc
21049 Bulk Product 29c2e401 Toys & Games $804.08 160 4.3 49 BULK-c1d2821a
21050 Bulk Product bea6e53a Electronics $502.20 492 2.3 76 BULK-3fdece4b
21051 Bulk Product 9c5f8aeb Books $930.38 362 4.2 72 BULK-4378f50d
21052 Bulk Product 49aa7461 Sports & Outdoors $390.91 142 1.3 9 BULK-4ef2169f
21053 Bulk Product a4aec75c Sports & Outdoors $255.68 129 4.1 11 BULK-afbb320f
21054 Bulk Product 872894fa Home & Garden $409.42 412 0.5 67 BULK-6b2bd323
21055 Bulk Product 83139fab Toys & Games $461.00 151 1.9 14 BULK-7ab28cb5
21056 Bulk Product 52b7a9ee Books $224.25 375 0.9 43 BULK-2e5c91b5
21057 Bulk Product 511892ed Sports & Outdoors $222.23 38 3.9 96 BULK-03d5025d
21058 Bulk Product 45031d8c Electronics $693.14 375 3.5 4 BULK-85f30089
21059 Bulk Product 2655d29e Electronics $24.45 36 0.4 60 BULK-0c2ea8a7
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