Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 18110 | Bulk Product e5c031fc | Home & Garden | $972.30 | 466 | ★ 0.7 | 79 | BULK-815bc29d |
| 18111 | Bulk Product b285a284 | Books | $983.32 | 442 | ★ 0.9 | 87 | BULK-fa1aa8a5 |
| 18112 | Bulk Product f745becd | Electronics | $835.97 | 368 | ★ 4.0 | 56 | BULK-49a6c78f |
| 18113 | Bulk Product c2ef9546 | Home & Garden | $146.62 | 341 | ★ 2.6 | 51 | BULK-6d9f804d |
| 18114 | Bulk Product bc562ab0 | Electronics | $936.73 | 158 | ★ 4.2 | 73 | BULK-4decc869 |
| 18115 | Bulk Product 8c9306e1 | Sports & Outdoors | $30.43 | 421 | ★ 4.7 | 41 | BULK-94fc1103 |
| 18116 | Bulk Product c7a8a7d2 | Home & Garden | $570.17 | 480 | ★ 3.9 | 16 | BULK-05f08997 |
| 18117 | Bulk Product 8b0661fb | Clothing | $675.93 | 28 | ★ 0.4 | 66 | BULK-0021aa76 |
| 18118 | Bulk Product 87f1471f | Home & Garden | $806.06 | 261 | ★ 0.5 | 79 | BULK-b6e38371 |
| 18119 | Bulk Product afcda75e | Clothing | $361.73 | 448 | ★ 1.4 | 49 | BULK-9ed98e1a |
| 18120 | Bulk Product 24cee67b | Books | $196.89 | 79 | ★ 3.6 | 36 | BULK-aa7b8732 |
| 18121 | Bulk Product f3607bf8 | Books | $363.58 | 13 | ★ 0.6 | 47 | BULK-4a6ec724 |
| 18122 | Bulk Product 59ac3161 | Home & Garden | $531.97 | 298 | ★ 4.4 | 98 | BULK-aa4620a0 |
| 18123 | Bulk Product cacf7584 | Home & Garden | $753.18 | 447 | ★ 1.4 | 91 | BULK-2d417787 |
| 18124 | Bulk Product e81b8c2a | Home & Garden | $284.91 | 35 | ★ 4.1 | 22 | BULK-00b24ebc |
| 18125 | Bulk Product 49400556 | Sports & Outdoors | $131.01 | 429 | ★ 2.4 | 87 | BULK-2e5bf5f3 |
| 18126 | Bulk Product becbf2b0 | Toys & Games | $987.78 | 459 | ★ 1.3 | 52 | BULK-90116307 |
| 18127 | Bulk Product da1ae14a | Books | $666.98 | 474 | ★ 1.7 | 7 | BULK-52cdc6d2 |
| 18128 | Bulk Product 000585c4 | Electronics | $832.73 | 177 | ★ 1.1 | 84 | BULK-07747760 |
| 18129 | Bulk Product 87807259 | Home & Garden | $955.14 | 160 | ★ 1.6 | 22 | BULK-dde63cc2 |
| 18130 | Bulk Product 98205a24 | Home & Garden | $634.88 | 333 | ★ 3.1 | 78 | BULK-038c4879 |
| 18131 | Bulk Product 680d13f4 | Clothing | $528.22 | 459 | ★ 0.9 | 4 | BULK-7432d1be |
| 18132 | Bulk Product 5cab1414 | Sports & Outdoors | $718.13 | 409 | ★ 3.4 | 8 | BULK-2598fe63 |
| 18133 | Bulk Product 6d548688 | Clothing | $961.66 | 12 | ★ 3.1 | 58 | BULK-a2080ad4 |
| 18134 | Bulk Product d29baa8d | Toys & Games | $267.76 | 45 | ★ 2.1 | 11 | BULK-a00fb8cf |
| 18135 | Bulk Product 021c572b | Home & Garden | $728.89 | 12 | ★ 2.3 | 0 | BULK-4eceb4ba |
| 18136 | Bulk Product f986e501 | Sports & Outdoors | $689.11 | 462 | ★ 0.4 | 41 | BULK-50a6eeae |
| 18137 | Bulk Product 2466f262 | Electronics | $313.77 | 305 | ★ 4.7 | 6 | BULK-d419c984 |
| 18138 | Bulk Product 596de547 | Books | $659.18 | 193 | ★ 0.8 | 67 | BULK-8883374d |
| 18139 | Bulk Product 38c647bc | Electronics | $15.66 | 296 | ★ 1.9 | 41 | BULK-cbc92f56 |
| 18140 | Bulk Product 90e12cb1 | Books | $963.77 | 216 | ★ 4.1 | 4 | BULK-d4732d14 |
| 18141 | Bulk Product 2d48ce33 | Home & Garden | $53.25 | 469 | ★ 0.6 | 7 | BULK-2f30d006 |
| 18142 | Bulk Product 2a414676 | Sports & Outdoors | $773.08 | 57 | ★ 3.5 | 93 | BULK-78080d1d |
| 18143 | Bulk Product 8aa34809 | Electronics | $247.07 | 375 | ★ 3.6 | 37 | BULK-f6ed7475 |
| 18144 | Bulk Product 6bb76ebf | Clothing | $228.40 | 202 | ★ 1.9 | 8 | BULK-9445807e |
| 18145 | Bulk Product b1292e99 | Electronics | $550.69 | 324 | ★ 4.3 | 56 | BULK-319735cb |
| 18146 | Bulk Product 72cc42d5 | Sports & Outdoors | $283.39 | 115 | ★ 4.5 | 45 | BULK-90e51ecb |
| 18147 | Bulk Product b27ed9d3 | Toys & Games | $209.89 | 358 | ★ 3.5 | 63 | BULK-b979a1c4 |
| 18148 | Bulk Product af9c3168 | Home & Garden | $95.45 | 276 | ★ 4.5 | 24 | BULK-880af438 |
| 18149 | Bulk Product 86d2f570 | Home & Garden | $424.27 | 482 | ★ 4.6 | 28 | BULK-278eccf8 |
| 18150 | Bulk Product 92e74ca8 | Clothing | $556.17 | 24 | ★ 5.0 | 73 | BULK-0a126e47 |
| 18151 | Bulk Product 3d79da44 | Sports & Outdoors | $601.18 | 267 | ★ 3.8 | 64 | BULK-557d2a86 |
| 18152 | Bulk Product 3236a27c | Toys & Games | $988.55 | 398 | ★ 4.9 | 7 | BULK-5671b0c3 |
| 18153 | Bulk Product 9fb847dc | Clothing | $411.65 | 467 | ★ 3.8 | 83 | BULK-735dcdad |
| 18154 | Bulk Product 75fc1081 | Home & Garden | $458.43 | 259 | ★ 4.5 | 24 | BULK-e4e9dc91 |
| 18155 | Bulk Product 499d2c4c | Clothing | $193.51 | 112 | ★ 2.5 | 99 | BULK-e306cd5c |
| 18156 | Bulk Product 7c1278d8 | Clothing | $408.59 | 398 | ★ 1.4 | 69 | BULK-324db712 |
| 18157 | Bulk Product a8937bc6 | Books | $939.75 | 126 | ★ 2.2 | 98 | BULK-ae099b2d |
| 18158 | Bulk Product a15e962c | Electronics | $463.03 | 373 | ★ 0.5 | 44 | BULK-bc33d707 |
| 18159 | Bulk Product e8429e67 | Home & Garden | $451.53 | 269 | ★ 4.0 | 73 | BULK-c8353c40 |
// 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
};
}