Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 24810 | Bulk Product 0e4fd70c | Sports & Outdoors | $192.28 | 150 | ★ 1.4 | 16 | BULK-774c56cb |
| 24811 | Bulk Product 08683da8 | Books | $13.55 | 80 | ★ 2.8 | 86 | BULK-7f950f01 |
| 24812 | Bulk Product f1255c6e | Electronics | $804.00 | 413 | ★ 0.1 | 90 | BULK-242f44f6 |
| 24813 | Bulk Product 459bda96 | Electronics | $235.57 | 434 | ★ 4.5 | 7 | BULK-d804f727 |
| 24814 | Bulk Product 2ba37fb3 | Sports & Outdoors | $28.36 | 184 | ★ 4.2 | 28 | BULK-d2d1a1a3 |
| 24815 | Bulk Product d8b2f526 | Electronics | $968.86 | 408 | ★ 4.6 | 4 | BULK-7d417db0 |
| 24816 | Bulk Product 9b3f1e3f | Books | $626.86 | 26 | ★ 1.4 | 66 | BULK-aeecafec |
| 24817 | Bulk Product 943116f1 | Electronics | $176.33 | 337 | ★ 2.5 | 71 | BULK-af6c4b7a |
| 24818 | Bulk Product 813e4b9f | Toys & Games | $340.16 | 115 | ★ 0.6 | 24 | BULK-c797499e |
| 24819 | Bulk Product 3e191778 | Electronics | $231.35 | 350 | ★ 0.5 | 91 | BULK-50e8e35a |
| 24820 | Bulk Product b6310b61 | Electronics | $729.87 | 406 | ★ 0.3 | 44 | BULK-d542c561 |
| 24821 | Bulk Product ab9f9eff | Books | $665.25 | 372 | ★ 4.2 | 32 | BULK-fbf860fc |
| 24822 | Bulk Product 9aaf7609 | Home & Garden | $178.72 | 456 | ★ 2.1 | 7 | BULK-71761a6a |
| 24823 | Bulk Product e911d61d | Toys & Games | $634.38 | 126 | ★ 1.7 | 53 | BULK-dba464b5 |
| 24824 | Bulk Product a4870488 | Sports & Outdoors | $109.06 | 301 | ★ 1.0 | 22 | BULK-57a1e824 |
| 24825 | Bulk Product 64eaedc8 | Sports & Outdoors | $671.89 | 330 | ★ 1.3 | 45 | BULK-71f1f09e |
| 24826 | Bulk Product 92012c5b | Clothing | $528.14 | 297 | ★ 4.4 | 31 | BULK-743fd3d4 |
| 24827 | Bulk Product 5d3e3cf8 | Books | $86.14 | 97 | ★ 3.0 | 11 | BULK-180e237f |
| 24828 | Bulk Product 1b2c6e87 | Toys & Games | $909.01 | 46 | ★ 0.7 | 43 | BULK-f3b3126c |
| 24829 | Bulk Product b9775a3f | Clothing | $324.46 | 486 | ★ 4.0 | 77 | BULK-e98640d1 |
| 24830 | Bulk Product 62cb264d | Sports & Outdoors | $525.39 | 11 | ★ 3.4 | 27 | BULK-5c0f2460 |
| 24831 | Bulk Product bbf8bcfa | Electronics | $901.09 | 218 | ★ 0.3 | 95 | BULK-42fa790d |
| 24832 | Bulk Product b30cef41 | Home & Garden | $81.48 | 447 | ★ 4.8 | 19 | BULK-4030cd45 |
| 24833 | Bulk Product 9993250f | Clothing | $288.34 | 379 | ★ 4.8 | 73 | BULK-d9a63df7 |
| 24834 | Bulk Product 051a05e6 | Sports & Outdoors | $49.24 | 230 | ★ 3.7 | 74 | BULK-dd2f3483 |
| 24835 | Bulk Product b4840fe0 | Clothing | $85.23 | 27 | ★ 2.6 | 89 | BULK-1af6a041 |
| 24836 | Bulk Product a043287a | Books | $628.57 | 208 | ★ 0.6 | 72 | BULK-fc1e40dd |
| 24837 | Bulk Product 362a5564 | Sports & Outdoors | $709.91 | 199 | ★ 1.8 | 13 | BULK-cdc503d9 |
| 24838 | Bulk Product 12f2c990 | Electronics | $940.84 | 24 | ★ 1.2 | 0 | BULK-5d14a4a8 |
| 24839 | Bulk Product e38bcc87 | Books | $335.80 | 372 | ★ 4.6 | 60 | BULK-480136ff |
| 24840 | Bulk Product f21c46a8 | Sports & Outdoors | $735.27 | 426 | ★ 3.6 | 36 | BULK-6e905b1f |
| 24841 | Bulk Product 0b2ee2d2 | Sports & Outdoors | $511.72 | 115 | ★ 0.6 | 99 | BULK-0640ea3b |
| 24842 | Bulk Product 7ab1789d | Clothing | $691.43 | 446 | ★ 4.5 | 64 | BULK-1febf8e9 |
| 24843 | Bulk Product e5560fd0 | Books | $620.30 | 205 | ★ 0.7 | 89 | BULK-01ff9962 |
| 24844 | Bulk Product fe2d0ab0 | Home & Garden | $411.41 | 268 | ★ 3.9 | 40 | BULK-66669173 |
| 24845 | Bulk Product 5203fecb | Sports & Outdoors | $401.54 | 23 | ★ 2.2 | 25 | BULK-fd9ae4e0 |
| 24846 | Bulk Product 39f9a561 | Sports & Outdoors | $339.87 | 321 | ★ 4.0 | 87 | BULK-f351fe80 |
| 24847 | Bulk Product d9fae204 | Sports & Outdoors | $468.33 | 184 | ★ 4.9 | 11 | BULK-b8657350 |
| 24848 | Bulk Product 74f48ff8 | Books | $868.89 | 252 | ★ 3.0 | 51 | BULK-07165de2 |
| 24849 | Bulk Product f19794e5 | Home & Garden | $172.85 | 5 | ★ 2.5 | 61 | BULK-5fe2406f |
| 24850 | Bulk Product 532e4f53 | Clothing | $229.27 | 361 | ★ 4.2 | 64 | BULK-16eea98c |
| 24851 | Bulk Product 1f7f92f7 | Books | $847.71 | 336 | ★ 2.2 | 89 | BULK-a850dc9b |
| 24852 | Bulk Product 6c0a09cd | Home & Garden | $888.67 | 389 | ★ 1.9 | 55 | BULK-43ecd170 |
| 24853 | Bulk Product eeeac47f | Sports & Outdoors | $94.43 | 439 | ★ 2.5 | 50 | BULK-f4a8f81a |
| 24854 | Bulk Product 7933be8c | Sports & Outdoors | $623.76 | 198 | ★ 1.6 | 66 | BULK-b90c418e |
| 24855 | Bulk Product c44f2c18 | Home & Garden | $591.46 | 263 | ★ 3.9 | 16 | BULK-12fd970f |
| 24856 | Bulk Product 354a99c1 | Books | $32.57 | 259 | ★ 3.7 | 28 | BULK-e4ce2c5d |
| 24857 | Bulk Product cd2a8bf1 | Sports & Outdoors | $721.29 | 485 | ★ 2.8 | 3 | BULK-f95a170d |
| 24858 | Bulk Product f07fbcac | Books | $569.07 | 437 | ★ 1.0 | 31 | BULK-ab4833df |
| 24859 | Bulk Product 5ab1ff1f | Sports & Outdoors | $409.49 | 43 | ★ 2.5 | 94 | BULK-11ba8611 |
// 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
};
}