Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

26 ms

Page Size

50

Current Page

424 / 489

Total Records

24441

Items per page: 25 50 100 200

Page 424 Results Showing 21151 - 21200 of 24441

ID Name Category Price Stock Rating Reviews SKU
21710 Bulk Product b46ca3e1 Books $580.18 123 4.6 17 BULK-580dcce3
21711 Bulk Product 1bfbb7c8 Sports & Outdoors $351.44 228 2.7 53 BULK-06d35484
21712 Bulk Product aebda95d Home & Garden $507.20 115 0.3 26 BULK-4512d426
21713 Bulk Product 73695f39 Electronics $922.74 129 0.3 10 BULK-6445c09d
21714 Bulk Product 6e3292a9 Toys & Games $804.20 307 3.8 79 BULK-4422c5bb
21715 Bulk Product 39d4952a Home & Garden $524.66 253 4.9 41 BULK-03d081fa
21716 Bulk Product c7cae469 Clothing $766.00 379 4.2 19 BULK-c2ce29bc
21717 Bulk Product 9c50f795 Toys & Games $566.39 83 3.3 9 BULK-ece6232f
21718 Bulk Product 3d4184c4 Toys & Games $985.72 114 3.8 82 BULK-dba8700b
21719 Bulk Product 2efde35e Clothing $601.18 293 1.4 45 BULK-f8ca0b2a
21720 Bulk Product c417492f Sports & Outdoors $896.07 59 0.9 31 BULK-eed9721d
21721 Bulk Product 4a907087 Clothing $747.83 393 4.3 11 BULK-0a6b741b
21722 Bulk Product c743f4b3 Home & Garden $640.02 242 3.4 80 BULK-4bf750dd
21723 Bulk Product 8c155ab0 Home & Garden $620.90 145 3.1 70 BULK-d291d83c
21724 Bulk Product bb64f9a3 Books $767.41 374 1.7 25 BULK-3370602c
21725 Bulk Product 0be04b0c Sports & Outdoors $47.57 401 3.4 78 BULK-c6a67d8f
21726 Bulk Product 882c6a51 Sports & Outdoors $990.90 126 4.9 93 BULK-f05e05d3
21727 Bulk Product 776237d9 Clothing $826.67 175 0.0 33 BULK-194adba5
21728 Bulk Product c3f1f6b2 Toys & Games $633.51 214 2.5 97 BULK-15b42257
21729 Bulk Product d5f41d0c Sports & Outdoors $757.57 360 1.1 72 BULK-dd93a982
21730 Bulk Product 03c221e8 Home & Garden $168.78 183 4.2 11 BULK-2c2c6d2a
21731 Bulk Product 177b7d81 Books $55.47 347 2.0 25 BULK-9836b1e5
21732 Bulk Product 8de07a0c Toys & Games $81.78 478 2.3 64 BULK-38cc7293
21733 Bulk Product 522a32de Home & Garden $355.44 3 1.9 6 BULK-bd7d0ed6
21734 Bulk Product e06a6d56 Toys & Games $331.54 75 1.2 90 BULK-95de1d4e
21735 Bulk Product 2fd1b33c Clothing $582.13 279 1.7 34 BULK-52b04c69
21736 Bulk Product c8f40fdf Sports & Outdoors $607.21 137 0.7 98 BULK-5cb71944
21737 Bulk Product ae5c8f59 Toys & Games $935.57 188 2.1 61 BULK-0687ae1e
21738 Bulk Product 7c761eb0 Books $977.08 272 1.1 86 BULK-9d2789c0
21739 Bulk Product a1d77029 Toys & Games $310.15 495 4.1 51 BULK-7d30034d
21740 Bulk Product 80f78f64 Clothing $338.87 18 1.4 47 BULK-0538e9c0
21741 Bulk Product aef12d54 Sports & Outdoors $667.96 327 0.5 87 BULK-a4902cec
21742 Bulk Product b7fb44a4 Clothing $504.33 311 1.1 76 BULK-ff81fe05
21743 Bulk Product ca57bf66 Toys & Games $185.50 145 0.9 52 BULK-76f03ce7
21744 Bulk Product f33a9a68 Books $259.98 314 1.0 87 BULK-c3ccb662
21745 Bulk Product 7dc676cf Clothing $432.39 271 4.2 27 BULK-a9134205
21746 Bulk Product 3800554f Home & Garden $925.26 409 1.4 29 BULK-c17cba7e
21747 Bulk Product ea221ab6 Home & Garden $771.63 425 2.3 61 BULK-6f64a120
21748 Bulk Product 636cb99d Clothing $384.52 149 2.9 98 BULK-21721822
21749 Bulk Product 86e50aa4 Books $186.48 435 1.0 76 BULK-51053675
21750 Bulk Product 5a75ff8a Home & Garden $530.34 451 2.9 28 BULK-2842d435
21751 Bulk Product df01b07a Clothing $483.55 250 0.5 46 BULK-b67dd025
21752 Bulk Product 09de04d0 Electronics $349.67 201 0.9 3 BULK-3a7e0cb6
21753 Bulk Product c5751e73 Sports & Outdoors $93.89 101 0.3 51 BULK-1d9d1604
21754 Bulk Product 1c9b5cec Sports & Outdoors $852.46 337 2.2 97 BULK-288b069e
21755 Bulk Product 421c5f07 Electronics $902.68 225 4.6 3 BULK-63b8259f
21756 Bulk Product 9832ce49 Electronics $524.63 466 4.3 46 BULK-b9dfcee8
21757 Bulk Product 51e087a2 Clothing $599.42 129 2.2 29 BULK-e5a49360
21758 Bulk Product ca8cd650 Books $213.43 158 4.6 26 BULK-0975524a
21759 Bulk Product f61aa621 Electronics $437.51 282 4.8 24 BULK-65293858
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