Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

18 ms

Page Size

50

Current Page

399 / 489

Total Records

24441

Items per page: 25 50 100 200

Page 399 Results Showing 19901 - 19950 of 24441

ID Name Category Price Stock Rating Reviews SKU
20460 Bulk Product ab004cb0 Toys & Games $546.04 242 2.1 12 BULK-5d6461bb
20461 Bulk Product b4f95700 Toys & Games $554.77 78 4.3 87 BULK-02373b1c
20462 Bulk Product 8921034c Clothing $983.56 25 3.9 10 BULK-62a10a51
20463 Bulk Product 0350aace Clothing $151.44 93 2.5 53 BULK-073d52c8
20464 Bulk Product a081dd3c Sports & Outdoors $239.49 284 1.8 49 BULK-ca8b8d47
20465 Bulk Product 2d187a36 Electronics $826.72 11 1.9 52 BULK-8b13b7c8
20466 Bulk Product 70b3d6d8 Clothing $461.55 409 3.4 87 BULK-6d831bc2
20467 Bulk Product 1da7442a Clothing $523.08 19 3.2 50 BULK-3a2f799c
20468 Bulk Product ca242ea7 Books $863.19 490 4.5 36 BULK-6e3620ab
20469 Bulk Product da93eb9a Toys & Games $752.62 134 1.7 65 BULK-558799be
20470 Bulk Product 14a9c6a6 Clothing $964.47 16 1.2 66 BULK-6ae2b2e4
20471 Bulk Product 54929858 Clothing $230.70 333 4.0 97 BULK-6b05b291
20472 Bulk Product 5055cd55 Toys & Games $818.39 32 3.9 14 BULK-4bb59ec7
20473 Bulk Product 8cb92208 Home & Garden $96.67 332 2.8 61 BULK-425b2a9e
20474 Bulk Product 73531cdf Clothing $598.62 137 1.0 83 BULK-3e0e60d8
20475 Bulk Product d52dbedb Toys & Games $250.01 199 4.7 62 BULK-118dcc8e
20476 Bulk Product 1e15d96f Toys & Games $479.53 254 3.4 65 BULK-81c832b5
20477 Bulk Product 48d7e176 Clothing $426.44 396 2.2 19 BULK-6b78e465
20478 Bulk Product d5544782 Home & Garden $215.20 289 0.2 65 BULK-a986965d
20479 Bulk Product 42672996 Home & Garden $139.70 362 1.0 72 BULK-63852fde
20480 Bulk Product f62e13da Sports & Outdoors $640.91 407 3.0 82 BULK-8ddee902
20481 Bulk Product 8a58ffe5 Sports & Outdoors $705.13 487 4.5 23 BULK-cd1a65cd
20482 Bulk Product 06ab6e57 Clothing $577.46 319 1.4 52 BULK-abe267e0
20483 Bulk Product 873e6b54 Sports & Outdoors $538.22 130 2.3 13 BULK-f88079ad
20484 Bulk Product 4af0e173 Sports & Outdoors $135.11 24 3.5 57 BULK-976fe57a
20485 Bulk Product d5208f5a Books $61.11 22 2.2 61 BULK-27915c8c
20486 Bulk Product d4e713e5 Home & Garden $18.99 190 0.7 9 BULK-9eca0eb7
20487 Bulk Product 7d0db8f2 Electronics $786.43 461 4.3 38 BULK-1ce85a32
20488 Bulk Product f56e9c5b Books $742.15 177 5.0 5 BULK-73b28aca
20489 Bulk Product 85abf5f0 Clothing $164.15 491 1.2 50 BULK-4100f557
20490 Bulk Product f26d0130 Clothing $942.64 386 0.3 62 BULK-e4256827
20491 Bulk Product db148696 Clothing $831.07 340 1.7 21 BULK-66ef1b9d
20492 Bulk Product 191c8a9d Toys & Games $830.20 373 2.0 27 BULK-cbd39662
20493 Bulk Product 0db7e2b6 Toys & Games $697.52 486 2.7 26 BULK-588bc075
20494 Bulk Product 2583bec6 Sports & Outdoors $266.27 165 2.0 51 BULK-035ae6b9
20495 Bulk Product f98bc016 Home & Garden $727.25 332 4.1 40 BULK-9b2423fb
20496 Bulk Product 3646c336 Sports & Outdoors $737.90 92 0.3 45 BULK-4d219c8f
20497 Bulk Product cc3cfd96 Sports & Outdoors $466.99 31 4.8 80 BULK-7b51c819
20498 Bulk Product 0c1d5356 Home & Garden $843.80 240 0.6 31 BULK-2d255c99
20499 Bulk Product 363e3c7a Clothing $904.04 283 2.2 41 BULK-e4874fd5
20500 Bulk Product 1c9c480e Sports & Outdoors $590.18 376 1.2 88 BULK-e87ae13f
20501 Bulk Product 6983c70f Electronics $335.63 222 2.1 80 BULK-64294ee1
20502 Bulk Product 2cd9c67e Books $739.74 386 2.7 44 BULK-1e4fd927
20503 Bulk Product 6c175015 Home & Garden $210.77 106 2.6 92 BULK-5a7d9572
20504 Bulk Product c231ab08 Clothing $270.98 441 0.7 10 BULK-cc899d10
20505 Bulk Product 2ae29b85 Home & Garden $743.44 370 4.9 39 BULK-1f20da04
20506 Bulk Product 8c2ea5e8 Sports & Outdoors $66.94 367 4.5 6 BULK-046deecf
20507 Bulk Product 69713f44 Sports & Outdoors $639.38 140 2.8 96 BULK-ea4614fd
20508 Bulk Product c9b87c97 Electronics $447.52 412 1.1 14 BULK-30344a39
20509 Bulk Product 8e7d3522 Toys & Games $850.44 48 0.0 27 BULK-9a4601b6
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