Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 15210 | Bulk Product f1bd847b | Toys & Games | $448.60 | 346 | ★ 0.2 | 3 | BULK-4a89a3b6 |
| 15211 | Bulk Product 8195b366 | Toys & Games | $182.60 | 341 | ★ 1.2 | 30 | BULK-536f63e3 |
| 15212 | Bulk Product 3221871f | Electronics | $107.41 | 277 | ★ 4.7 | 36 | BULK-07ebc2db |
| 15213 | Bulk Product 00b3909e | Home & Garden | $897.66 | 316 | ★ 2.1 | 5 | BULK-49efd8bc |
| 15214 | Bulk Product 3c458bbf | Home & Garden | $956.62 | 165 | ★ 3.6 | 71 | BULK-7a7a2949 |
| 15215 | Bulk Product 762aa9d3 | Home & Garden | $897.59 | 225 | ★ 0.7 | 50 | BULK-bc627f4f |
| 15216 | Bulk Product 47bbf8de | Sports & Outdoors | $397.47 | 290 | ★ 3.9 | 54 | BULK-29c1ee61 |
| 15217 | Bulk Product 3808980e | Electronics | $569.01 | 5 | ★ 3.3 | 90 | BULK-ec4f0f8e |
| 15218 | Bulk Product 7f99520a | Toys & Games | $790.23 | 440 | ★ 1.0 | 20 | BULK-6d04bc12 |
| 15219 | Bulk Product 850f4488 | Toys & Games | $261.66 | 77 | ★ 4.5 | 16 | BULK-1004b136 |
| 15220 | Bulk Product ed7d4edf | Clothing | $561.70 | 317 | ★ 1.5 | 8 | BULK-70017955 |
| 15221 | Bulk Product e8bc18e4 | Electronics | $270.50 | 191 | ★ 4.0 | 80 | BULK-41a5c65a |
| 15222 | Bulk Product 4d3807f7 | Toys & Games | $868.11 | 107 | ★ 2.8 | 30 | BULK-9aa09d99 |
| 15223 | Bulk Product 3bf5b4a0 | Clothing | $807.68 | 132 | ★ 2.1 | 5 | BULK-dc79b8a0 |
| 15224 | Bulk Product c9966b93 | Sports & Outdoors | $773.80 | 410 | ★ 0.2 | 48 | BULK-56bb7b08 |
| 15225 | Bulk Product dc614582 | Clothing | $873.07 | 116 | ★ 2.7 | 2 | BULK-e3d8efee |
| 15226 | Bulk Product be2f8072 | Sports & Outdoors | $965.95 | 417 | ★ 4.0 | 40 | BULK-979c193b |
| 15227 | Bulk Product 0b094283 | Electronics | $203.20 | 494 | ★ 1.1 | 93 | BULK-4c08a294 |
| 15228 | Bulk Product 41b8a13a | Clothing | $11.06 | 199 | ★ 1.4 | 53 | BULK-807ed53b |
| 15229 | Bulk Product 2e40acf4 | Electronics | $933.42 | 210 | ★ 0.5 | 64 | BULK-23e47e18 |
| 15230 | Bulk Product 5a4ce5de | Home & Garden | $884.04 | 460 | ★ 2.7 | 63 | BULK-b8c253d5 |
| 15231 | Bulk Product 2710e959 | Toys & Games | $993.67 | 405 | ★ 4.3 | 24 | BULK-0d404b96 |
| 15232 | Bulk Product 553b7059 | Electronics | $505.58 | 459 | ★ 1.3 | 35 | BULK-c2420393 |
| 15233 | Bulk Product 95122b33 | Toys & Games | $118.48 | 16 | ★ 2.2 | 74 | BULK-3e65128a |
| 15234 | Bulk Product 24658c2f | Clothing | $997.22 | 266 | ★ 1.7 | 41 | BULK-64585c4e |
| 15235 | Bulk Product ec60c44c | Clothing | $654.59 | 271 | ★ 2.3 | 40 | BULK-c08ec34a |
| 15236 | Bulk Product 051d30c2 | Books | $859.16 | 242 | ★ 1.9 | 97 | BULK-fc1a74b6 |
| 15237 | Bulk Product e5ea121f | Books | $312.01 | 142 | ★ 3.0 | 62 | BULK-b260f36b |
| 15238 | Bulk Product 9bfff0f7 | Toys & Games | $143.36 | 463 | ★ 3.6 | 96 | BULK-76a9ea40 |
| 15239 | Bulk Product bcddc142 | Clothing | $228.13 | 259 | ★ 2.9 | 89 | BULK-c638efe1 |
| 15240 | Bulk Product 7d33e287 | Books | $174.47 | 403 | ★ 4.2 | 90 | BULK-8708fd8b |
| 15241 | Bulk Product 7525b6d8 | Sports & Outdoors | $187.17 | 294 | ★ 3.0 | 12 | BULK-98672f5a |
| 15242 | Bulk Product e630df6e | Sports & Outdoors | $465.42 | 66 | ★ 4.0 | 12 | BULK-52fc4df5 |
| 15243 | Bulk Product 66d68c1c | Clothing | $77.43 | 385 | ★ 2.7 | 13 | BULK-4eb42c19 |
| 15244 | Bulk Product 7ebae1f5 | Home & Garden | $382.47 | 230 | ★ 4.3 | 38 | BULK-f0e5c497 |
| 15245 | Bulk Product 62d5ab1a | Toys & Games | $386.01 | 495 | ★ 0.6 | 91 | BULK-deee7b73 |
| 15246 | Bulk Product c33c7e4a | Electronics | $846.45 | 52 | ★ 0.6 | 40 | BULK-12f57e4f |
| 15247 | Bulk Product 0e3b6e77 | Clothing | $850.51 | 230 | ★ 1.1 | 16 | BULK-76e3afdd |
| 15248 | Bulk Product 914b69e5 | Clothing | $528.85 | 183 | ★ 2.2 | 23 | BULK-30312bcb |
| 15249 | Bulk Product b41e4744 | Books | $429.31 | 146 | ★ 2.1 | 95 | BULK-fb4597bc |
| 15250 | Bulk Product 7a9c13de | Books | $346.87 | 191 | ★ 3.8 | 28 | BULK-fc263c2e |
| 15251 | Bulk Product 492962f2 | Sports & Outdoors | $871.71 | 485 | ★ 4.8 | 58 | BULK-bc647fb1 |
| 15252 | Bulk Product 5f86a8b2 | Toys & Games | $498.53 | 59 | ★ 4.7 | 74 | BULK-7e7ac5e9 |
| 15253 | Bulk Product 1f680562 | Toys & Games | $177.01 | 429 | ★ 4.3 | 19 | BULK-3ae77fa0 |
| 15254 | Bulk Product 85261cd2 | Toys & Games | $798.88 | 131 | ★ 0.6 | 61 | BULK-d94400d1 |
| 15255 | Bulk Product c484e30e | Toys & Games | $320.68 | 119 | ★ 0.3 | 98 | BULK-00f85356 |
| 15256 | Bulk Product 520c1a7c | Toys & Games | $318.92 | 389 | ★ 4.8 | 69 | BULK-938b59cc |
| 15257 | Bulk Product a541f8f4 | Sports & Outdoors | $335.93 | 133 | ★ 4.3 | 2 | BULK-1151670b |
| 15258 | Bulk Product 4de4e597 | Sports & Outdoors | $106.95 | 243 | ★ 2.1 | 63 | BULK-7ff386f6 |
| 15259 | Bulk Product 920fcc5c | Clothing | $340.53 | 403 | ★ 4.7 | 75 | BULK-d3a7b2cd |
// 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
};
}