Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

20 ms

Page Size

50

Current Page

191 / 489

Total Records

24441

Items per page: 25 50 100 200

Page 191 Results Showing 9501 - 9550 of 24441

ID Name Category Price Stock Rating Reviews SKU
10060 Bulk Product 716b0331 Sports & Outdoors $498.29 7 3.6 70 BULK-029b19f6
10061 Bulk Product 2c2a3444 Toys & Games $853.01 166 4.0 94 BULK-e93d38ff
10062 Bulk Product ed1fe035 Home & Garden $268.61 109 1.4 61 BULK-03e46848
10063 Bulk Product 272533a5 Home & Garden $610.19 3 0.2 18 BULK-fedf4565
10064 Bulk Product fa418b6a Sports & Outdoors $715.11 255 1.4 98 BULK-d8da9013
10065 Bulk Product 51f7cf17 Sports & Outdoors $508.75 260 1.0 33 BULK-7cd27e52
10066 Bulk Product 5e39bc02 Home & Garden $892.57 237 3.9 26 BULK-24eea4dd
10067 Bulk Product fc3af787 Toys & Games $746.10 228 2.9 21 BULK-418c039d
10068 Bulk Product 57a5482e Sports & Outdoors $896.51 115 2.8 63 BULK-72d231eb
10069 Bulk Product f52d73ed Books $214.64 443 1.8 13 BULK-791352d6
10070 Bulk Product 44ef1a49 Electronics $870.96 459 4.8 86 BULK-a7db6639
10071 Bulk Product 8c908784 Sports & Outdoors $538.43 306 3.3 8 BULK-9c540fb9
10072 Bulk Product fc0ace7d Electronics $11.83 399 4.3 87 BULK-7d4ed941
10073 Bulk Product 3c1bc4fc Books $907.01 314 3.1 69 BULK-fc9c6e22
10074 Bulk Product 63965252 Home & Garden $793.23 214 1.5 99 BULK-74b04a97
10075 Bulk Product 9397ff58 Clothing $621.39 434 0.1 14 BULK-95c977c0
10076 Bulk Product 496d1cb6 Books $262.73 402 4.0 69 BULK-d9c4e94b
10077 Bulk Product 7cdc8872 Home & Garden $408.49 130 3.9 41 BULK-32b97491
10078 Bulk Product 4381e9a5 Clothing $670.30 439 4.4 54 BULK-bb52eb04
10079 Bulk Product 9c180c2a Electronics $64.37 197 0.7 88 BULK-9c70b089
10080 Bulk Product e879eb48 Home & Garden $628.38 314 0.7 92 BULK-7a60d353
10081 Bulk Product 72bd3aab Clothing $15.53 121 2.7 13 BULK-0b260aa5
10082 Bulk Product 093fedef Electronics $36.30 61 2.6 59 BULK-7f2134f6
10083 Bulk Product 51255878 Clothing $123.45 420 4.5 39 BULK-9dab6d7d
10084 Bulk Product 5dcae3d9 Home & Garden $616.18 438 3.3 43 BULK-feeb79c3
10085 Bulk Product b6fc3848 Electronics $814.27 107 2.2 37 BULK-b7bf3c11
10086 Bulk Product 5d71129c Electronics $620.98 426 0.8 97 BULK-84380806
10087 Bulk Product 1dc0bbe2 Home & Garden $401.80 341 2.6 22 BULK-16daf0da
10088 Bulk Product e7f7c254 Books $986.57 145 4.5 64 BULK-4742b3be
10089 Bulk Product d4773c00 Sports & Outdoors $932.30 379 3.6 46 BULK-37cffd59
10090 Bulk Product 3de70a78 Clothing $740.41 70 4.6 69 BULK-2ed3b158
10091 Bulk Product aa6ca0a6 Toys & Games $792.99 295 1.1 4 BULK-9c2012bf
10092 Bulk Product 519a8dd2 Electronics $945.99 294 4.9 27 BULK-a4e915b9
10093 Bulk Product 04974992 Clothing $776.98 335 0.1 60 BULK-5bd002df
10094 Bulk Product fdbdc967 Electronics $219.10 65 4.4 2 BULK-f0ab004c
10095 Bulk Product 6bd39f96 Electronics $659.33 247 2.5 72 BULK-1fcf3a58
10096 Bulk Product aa7f4d91 Books $434.90 79 1.5 74 BULK-45c577b8
10097 Bulk Product 8b35986d Home & Garden $893.97 451 0.6 32 BULK-bcfb0840
10098 Bulk Product 1de29edc Toys & Games $895.80 394 1.2 62 BULK-f336ca9d
10099 Bulk Product 707b863b Clothing $868.84 265 2.6 63 BULK-e3844f18
10100 Bulk Product 71b484d5 Sports & Outdoors $562.00 139 0.2 7 BULK-e2b423bd
10101 Bulk Product 89351264 Toys & Games $551.60 470 1.6 68 BULK-46b19232
10102 Bulk Product 6ca89472 Sports & Outdoors $707.09 391 0.4 21 BULK-8a5d56f3
10103 Bulk Product 71c340d4 Sports & Outdoors $154.05 112 2.0 60 BULK-ad65038d
10104 Bulk Product f54bf9d0 Books $757.56 419 0.0 87 BULK-882a473b
10105 Bulk Product 629869e8 Books $752.35 250 4.7 81 BULK-2d3d01dd
10106 Bulk Product a94421f4 Home & Garden $271.25 80 3.2 55 BULK-f3a2a0a2
10107 Bulk Product c9d370b8 Electronics $512.35 1 3.4 62 BULK-54e077d9
10108 Bulk Product a4df1b59 Books $541.98 392 2.5 84 BULK-6f4d3ddf
10109 Bulk Product b469df8c Toys & Games $156.83 160 4.0 46 BULK-12bac3ca
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