Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 20360 | Bulk Product 4198bc98 | Clothing | $831.65 | 140 | ★ 3.1 | 10 | BULK-9240c0ad |
| 20361 | Bulk Product 57f2f12a | Home & Garden | $439.45 | 128 | ★ 3.4 | 58 | BULK-91287ada |
| 20362 | Bulk Product ea78440b | Sports & Outdoors | $408.54 | 248 | ★ 2.3 | 84 | BULK-7a77c093 |
| 20363 | Bulk Product e593d1ad | Toys & Games | $163.26 | 449 | ★ 0.4 | 68 | BULK-ee9ffef3 |
| 20364 | Bulk Product 2602ceef | Sports & Outdoors | $697.04 | 169 | ★ 3.4 | 36 | BULK-761afc58 |
| 20365 | Bulk Product ecd5327a | Sports & Outdoors | $923.62 | 259 | ★ 4.0 | 74 | BULK-b52ed7a9 |
| 20366 | Bulk Product f73d459d | Electronics | $650.31 | 394 | ★ 4.9 | 11 | BULK-48d30073 |
| 20367 | Bulk Product c7f210eb | Electronics | $332.24 | 221 | ★ 1.3 | 19 | BULK-b39082fa |
| 20368 | Bulk Product 5fe7560e | Sports & Outdoors | $562.35 | 227 | ★ 0.8 | 72 | BULK-56004986 |
| 20369 | Bulk Product c55bfc5b | Clothing | $474.64 | 15 | ★ 3.9 | 13 | BULK-61702643 |
| 20370 | Bulk Product c4aeef3b | Toys & Games | $511.06 | 113 | ★ 0.1 | 87 | BULK-8e9581a3 |
| 20371 | Bulk Product ded54f7f | Home & Garden | $625.65 | 76 | ★ 3.6 | 67 | BULK-a09d93d9 |
| 20372 | Bulk Product ee59100b | Toys & Games | $157.18 | 453 | ★ 4.5 | 97 | BULK-7c033e23 |
| 20373 | Bulk Product 00a15f37 | Sports & Outdoors | $768.99 | 483 | ★ 3.5 | 10 | BULK-b4bd647b |
| 20374 | Bulk Product 198e300e | Home & Garden | $529.11 | 332 | ★ 4.3 | 84 | BULK-cfa9cb27 |
| 20375 | Bulk Product e830fb32 | Sports & Outdoors | $874.44 | 483 | ★ 3.7 | 5 | BULK-dffc10c0 |
| 20376 | Bulk Product 3e679be4 | Home & Garden | $492.48 | 266 | ★ 4.6 | 84 | BULK-b9b05fe6 |
| 20377 | Bulk Product 879beef3 | Sports & Outdoors | $497.54 | 154 | ★ 1.7 | 10 | BULK-210789df |
| 20378 | Bulk Product 9da3098a | Clothing | $251.81 | 234 | ★ 1.4 | 0 | BULK-539386e1 |
| 20379 | Bulk Product 918e1f42 | Clothing | $978.39 | 233 | ★ 0.3 | 95 | BULK-2c9e619a |
| 20380 | Bulk Product b2903e8a | Books | $867.44 | 82 | ★ 1.2 | 11 | BULK-b622ca50 |
| 20381 | Bulk Product 099a2719 | Toys & Games | $660.22 | 313 | ★ 4.3 | 20 | BULK-021f36c2 |
| 20382 | Bulk Product 32c18845 | Electronics | $98.39 | 349 | ★ 1.8 | 9 | BULK-45bdc8b8 |
| 20383 | Bulk Product 45989c89 | Books | $326.88 | 343 | ★ 4.3 | 33 | BULK-57b726f2 |
| 20384 | Bulk Product 0de2f23a | Sports & Outdoors | $440.71 | 334 | ★ 4.7 | 46 | BULK-d44cb0d1 |
| 20385 | Bulk Product 48ae8141 | Toys & Games | $839.95 | 482 | ★ 3.5 | 77 | BULK-bb332684 |
| 20386 | Bulk Product 066bb65a | Electronics | $354.51 | 154 | ★ 0.1 | 86 | BULK-3a65eb3e |
| 20387 | Bulk Product fcbb9976 | Home & Garden | $785.78 | 163 | ★ 3.8 | 58 | BULK-e57b6f4f |
| 20388 | Bulk Product d910b38c | Toys & Games | $56.04 | 184 | ★ 4.8 | 79 | BULK-466e56ae |
| 20389 | Bulk Product 597f0089 | Electronics | $311.38 | 101 | ★ 0.9 | 48 | BULK-f6232fe5 |
| 20390 | Bulk Product 6ea73cca | Electronics | $561.97 | 320 | ★ 0.7 | 16 | BULK-5a430223 |
| 20391 | Bulk Product 75133815 | Electronics | $729.60 | 161 | ★ 0.8 | 35 | BULK-4b7acd8d |
| 20392 | Bulk Product 41d4bac5 | Sports & Outdoors | $120.59 | 358 | ★ 2.7 | 39 | BULK-2a632262 |
| 20393 | Bulk Product e2c1b124 | Electronics | $811.49 | 129 | ★ 4.2 | 7 | BULK-6f179920 |
| 20394 | Bulk Product 5e5c21f4 | Electronics | $173.68 | 488 | ★ 4.4 | 61 | BULK-63c01194 |
| 20395 | Bulk Product 5d655c6c | Clothing | $50.93 | 31 | ★ 0.8 | 18 | BULK-b35aa73b |
| 20396 | Bulk Product 43b0c459 | Home & Garden | $93.77 | 254 | ★ 1.5 | 35 | BULK-da874a93 |
| 20397 | Bulk Product baad641d | Sports & Outdoors | $81.62 | 44 | ★ 1.9 | 73 | BULK-494c64e2 |
| 20398 | Bulk Product 700d4902 | Electronics | $187.15 | 105 | ★ 0.9 | 72 | BULK-fa71ff24 |
| 20399 | Bulk Product e964ed95 | Toys & Games | $720.91 | 250 | ★ 2.0 | 68 | BULK-510759c0 |
| 20400 | Bulk Product 6ef5116d | Home & Garden | $260.66 | 498 | ★ 3.4 | 73 | BULK-b2d6f12b |
| 20401 | Bulk Product d4f6c19f | Clothing | $994.58 | 285 | ★ 0.3 | 96 | BULK-f4a6a108 |
| 20402 | Bulk Product ae6e93b9 | Toys & Games | $79.17 | 121 | ★ 4.5 | 29 | BULK-7edeab5d |
| 20403 | Bulk Product 3f2dffec | Clothing | $365.94 | 108 | ★ 1.1 | 73 | BULK-c399d9a6 |
| 20404 | Bulk Product 51316ae4 | Electronics | $682.74 | 46 | ★ 3.2 | 32 | BULK-70b76fbc |
| 20405 | Bulk Product 2f4a210d | Home & Garden | $793.02 | 122 | ★ 1.9 | 59 | BULK-5c5f13f9 |
| 20406 | Bulk Product 80f3c355 | Books | $733.45 | 424 | ★ 4.5 | 95 | BULK-4e3eb1a1 |
| 20407 | Bulk Product 2c4f9a8c | Books | $1,002.33 | 497 | ★ 0.5 | 12 | BULK-581d764c |
| 20408 | Bulk Product 6f7f4733 | Home & Garden | $256.88 | 230 | ★ 2.1 | 60 | BULK-495e1483 |
| 20409 | Bulk Product 28dd84b6 | Home & Garden | $387.91 | 403 | ★ 2.6 | 82 | BULK-3d17edb5 |
// 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
};
}