Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

79 ms

Page Size

50

Current Page

392 / 489

Total Records

24441

Items per page: 25 50 100 200

Page 392 Results Showing 19551 - 19600 of 24441

ID Name Category Price Stock Rating Reviews SKU
20110 Bulk Product ad2d10c3 Home & Garden $953.47 122 2.6 7 BULK-ba411020
20111 Bulk Product 2dcc1e37 Books $353.43 84 2.7 64 BULK-0f9506cb
20112 Bulk Product 793ec087 Books $19.14 89 1.8 7 BULK-7f370f60
20113 Bulk Product 0d001126 Electronics $560.25 272 1.3 57 BULK-b73cdd46
20114 Bulk Product 7a47031a Books $989.00 51 1.8 21 BULK-7aa382b4
20115 Bulk Product b7ee4a8e Clothing $677.74 87 4.4 7 BULK-470aa7ea
20116 Bulk Product 022bc6ef Toys & Games $437.71 431 1.2 73 BULK-1e67d77b
20117 Bulk Product 64a3839d Sports & Outdoors $745.30 61 2.9 62 BULK-88517353
20118 Bulk Product f6ba489a Clothing $979.11 44 3.2 24 BULK-7a36d8fc
20119 Bulk Product cb50f972 Clothing $713.52 469 3.9 22 BULK-fbd563a1
20120 Bulk Product 2d805505 Toys & Games $669.13 442 0.7 72 BULK-595532f5
20121 Bulk Product 2dfd78a4 Home & Garden $93.71 414 4.1 76 BULK-aa35931e
20122 Bulk Product 70b89aed Books $183.35 115 2.5 18 BULK-5c1515ad
20123 Bulk Product 75976f0a Sports & Outdoors $675.30 8 4.2 68 BULK-346a44bc
20124 Bulk Product e3d19a99 Electronics $580.90 274 0.6 72 BULK-1bbc6767
20125 Bulk Product 8ea52a9c Home & Garden $219.49 387 3.4 33 BULK-00cebeb6
20126 Bulk Product 83c323a2 Sports & Outdoors $781.72 456 1.8 34 BULK-3d345cf3
20127 Bulk Product 726e382b Home & Garden $861.55 308 1.1 16 BULK-297f8910
20128 Bulk Product e4dd47b0 Clothing $247.76 388 2.6 22 BULK-5273cc14
20129 Bulk Product b63f491f Electronics $525.68 109 4.5 64 BULK-a3d01064
20130 Bulk Product 206dc0ab Clothing $473.18 396 4.3 97 BULK-4d9a0446
20131 Bulk Product 4ae10a95 Books $15.01 354 4.7 86 BULK-a0974ba6
20132 Bulk Product 71f98769 Toys & Games $999.78 309 4.5 80 BULK-410f837b
20133 Bulk Product fb18688d Home & Garden $938.63 112 0.0 19 BULK-c511cafb
20134 Bulk Product 1362c7d9 Electronics $721.17 401 2.1 18 BULK-e693ba1d
20135 Bulk Product a14129ff Clothing $871.61 142 2.9 2 BULK-5c339672
20136 Bulk Product 060c9e71 Clothing $389.57 188 4.2 92 BULK-c9968990
20137 Bulk Product a53c7d03 Sports & Outdoors $976.90 482 3.6 72 BULK-505c9bd8
20138 Bulk Product bb11f24b Sports & Outdoors $581.93 48 4.6 56 BULK-85c3e60c
20139 Bulk Product 0b05b998 Clothing $301.99 66 1.1 76 BULK-8304c7a2
20140 Bulk Product 90c31c71 Clothing $742.45 424 1.8 42 BULK-03dc5ae1
20141 Bulk Product 8cd8732c Sports & Outdoors $311.87 293 0.4 24 BULK-e519a607
20142 Bulk Product 1e4cc122 Home & Garden $225.14 426 4.3 76 BULK-33d4e745
20143 Bulk Product 1cea2a5f Home & Garden $469.22 219 4.2 27 BULK-e0eae553
20144 Bulk Product 3e1c3cfc Books $533.97 235 2.4 66 BULK-75df8fd9
20145 Bulk Product ce1fc102 Sports & Outdoors $316.82 136 2.8 10 BULK-8ba61497
20146 Bulk Product 40721b36 Toys & Games $200.58 87 1.8 56 BULK-3f12a73a
20147 Bulk Product 363cce53 Sports & Outdoors $884.09 284 3.4 26 BULK-30412f47
20148 Bulk Product a4c7203f Electronics $219.68 38 0.5 89 BULK-806f5013
20149 Bulk Product eb57ce40 Clothing $630.37 215 2.8 46 BULK-eba64f6d
20150 Bulk Product b4bea90b Clothing $893.85 278 3.6 57 BULK-39ae6ac2
20151 Bulk Product 7c5457e0 Electronics $860.77 309 2.8 34 BULK-71e4801d
20152 Bulk Product 61e80596 Sports & Outdoors $153.79 274 2.6 79 BULK-a8699783
20153 Bulk Product 0443c280 Home & Garden $591.17 410 3.8 80 BULK-21a71253
20154 Bulk Product 33e4f3ac Toys & Games $417.94 486 2.3 92 BULK-38e576f4
20155 Bulk Product ddcc948a Books $135.41 249 2.7 76 BULK-08b9918a
20156 Bulk Product 901655c3 Clothing $105.62 75 4.3 20 BULK-87bc9554
20157 Bulk Product d7832a80 Clothing $402.47 259 1.9 50 BULK-c1c0c2c1
20158 Bulk Product cbbc75e8 Home & Garden $678.87 200 4.9 13 BULK-eac49edc
20159 Bulk Product 76923520 Clothing $230.72 280 2.7 4 BULK-e74ebd8b
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