Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 8410 | Bulk Product 61773802 | Home & Garden | $342.70 | 384 | ★ 2.9 | 59 | BULK-559d307a |
| 8411 | Bulk Product f7c1b5df | Home & Garden | $831.39 | 255 | ★ 1.4 | 43 | BULK-cc7b9a44 |
| 8412 | Bulk Product 41f173c2 | Books | $391.59 | 17 | ★ 1.8 | 58 | BULK-b42a8318 |
| 8413 | Bulk Product f5c535a0 | Home & Garden | $924.38 | 350 | ★ 4.7 | 30 | BULK-67a22937 |
| 8414 | Bulk Product 97aca415 | Clothing | $160.35 | 303 | ★ 1.1 | 16 | BULK-36ca6bbf |
| 8415 | Bulk Product 7f41e7f0 | Books | $554.70 | 77 | ★ 3.9 | 61 | BULK-5bb2bda4 |
| 8416 | Bulk Product 0350370a | Sports & Outdoors | $168.16 | 455 | ★ 3.6 | 89 | BULK-1ce5f40c |
| 8417 | Bulk Product 395691f9 | Clothing | $352.11 | 448 | ★ 3.5 | 40 | BULK-101f753f |
| 8418 | Bulk Product e15f2892 | Sports & Outdoors | $543.12 | 28 | ★ 0.7 | 61 | BULK-1e7403b4 |
| 8419 | Bulk Product eb5e4b0b | Toys & Games | $283.13 | 180 | ★ 1.2 | 87 | BULK-0ce62ac8 |
| 8420 | Bulk Product e78a5505 | Clothing | $26.23 | 290 | ★ 0.5 | 85 | BULK-8905ac61 |
| 8421 | Bulk Product ab20b64f | Books | $657.19 | 359 | ★ 4.8 | 98 | BULK-f81846a3 |
| 8422 | Bulk Product cc56c4bf | Home & Garden | $917.17 | 427 | ★ 0.8 | 5 | BULK-916a5c04 |
| 8423 | Bulk Product f71ebf6f | Sports & Outdoors | $275.21 | 76 | ★ 0.6 | 55 | BULK-608e93a8 |
| 8424 | Bulk Product e40d7790 | Books | $582.89 | 323 | ★ 0.9 | 5 | BULK-8318af98 |
| 8425 | Bulk Product 01e5149b | Toys & Games | $798.64 | 452 | ★ 1.1 | 98 | BULK-5188d87b |
| 8426 | Bulk Product 93ec752d | Clothing | $930.91 | 194 | ★ 4.8 | 86 | BULK-2e132bfc |
| 8427 | Bulk Product 5bb7bd2b | Sports & Outdoors | $944.99 | 393 | ★ 4.2 | 0 | BULK-9c1c1739 |
| 8428 | Bulk Product e7f9c33c | Electronics | $436.88 | 389 | ★ 1.0 | 20 | BULK-6e5cfbaa |
| 8429 | Bulk Product b069d7a8 | Home & Garden | $887.01 | 430 | ★ 2.6 | 16 | BULK-88c9437c |
| 8430 | Bulk Product c389a9b1 | Home & Garden | $419.96 | 345 | ★ 0.9 | 60 | BULK-0a7ce3c4 |
| 8431 | Bulk Product 4968588e | Clothing | $748.76 | 325 | ★ 0.1 | 39 | BULK-5488772c |
| 8432 | Bulk Product 39de1d58 | Sports & Outdoors | $798.54 | 132 | ★ 0.9 | 31 | BULK-03909a5b |
| 8433 | Bulk Product 059de47b | Toys & Games | $239.18 | 226 | ★ 2.4 | 56 | BULK-98e6ef30 |
| 8434 | Bulk Product 15218325 | Toys & Games | $946.10 | 105 | ★ 1.1 | 93 | BULK-f32f9529 |
| 8435 | Bulk Product 201075ac | Clothing | $269.24 | 66 | ★ 2.0 | 53 | BULK-48d60632 |
| 8436 | Bulk Product b9d34b4d | Sports & Outdoors | $443.73 | 489 | ★ 1.4 | 21 | BULK-e8c2f762 |
| 8437 | Bulk Product 85a2e19d | Books | $860.97 | 221 | ★ 0.8 | 28 | BULK-0ba0bf39 |
| 8438 | Bulk Product b2e43b0b | Books | $582.22 | 443 | ★ 4.0 | 2 | BULK-9e79ceb8 |
| 8439 | Bulk Product 821973fe | Books | $601.27 | 416 | ★ 1.5 | 4 | BULK-1e5427aa |
| 8440 | Bulk Product 6da63cfa | Home & Garden | $244.39 | 403 | ★ 4.5 | 34 | BULK-99acd301 |
| 8441 | Bulk Product 6c0566fb | Clothing | $408.88 | 411 | ★ 2.3 | 14 | BULK-e05ea1b0 |
| 8442 | Bulk Product d6e674e8 | Books | $593.05 | 143 | ★ 3.9 | 15 | BULK-66cd0e84 |
| 8443 | Bulk Product 7a639f80 | Electronics | $345.85 | 244 | ★ 4.6 | 41 | BULK-cadbde36 |
| 8444 | Bulk Product 82693dc6 | Toys & Games | $906.23 | 316 | ★ 3.4 | 85 | BULK-35494946 |
| 8445 | Bulk Product ab26065a | Books | $863.44 | 441 | ★ 1.3 | 90 | BULK-aca836f5 |
| 8446 | Bulk Product c0004bb4 | Books | $156.52 | 20 | ★ 2.0 | 82 | BULK-d7b1b826 |
| 8447 | Bulk Product 4f237186 | Clothing | $77.87 | 166 | ★ 3.1 | 34 | BULK-f670713c |
| 8448 | Bulk Product 13158210 | Toys & Games | $548.83 | 211 | ★ 3.1 | 12 | BULK-09cf4e73 |
| 8449 | Bulk Product a5d8555c | Home & Garden | $126.48 | 454 | ★ 1.1 | 18 | BULK-ab56f0d3 |
| 8450 | Bulk Product 8a3cbee6 | Books | $102.43 | 218 | ★ 4.9 | 67 | BULK-8ebe827e |
| 8451 | Bulk Product 5be17c0f | Clothing | $644.70 | 351 | ★ 2.6 | 79 | BULK-bbb13d45 |
| 8452 | Bulk Product aac23f9f | Clothing | $202.50 | 259 | ★ 3.2 | 89 | BULK-01d119fb |
| 8453 | Bulk Product c9e5465a | Electronics | $476.74 | 423 | ★ 2.7 | 10 | BULK-abe2d437 |
| 8454 | Bulk Product e3721393 | Sports & Outdoors | $141.53 | 327 | ★ 1.8 | 52 | BULK-848f24a8 |
| 8455 | Bulk Product 205e326f | Clothing | $1,007.56 | 348 | ★ 2.1 | 92 | BULK-3f01148c |
| 8456 | Bulk Product c799ded7 | Home & Garden | $965.78 | 451 | ★ 3.7 | 10 | BULK-7a77f9f5 |
| 8457 | Bulk Product 5b43fffc | Books | $305.85 | 256 | ★ 3.8 | 70 | BULK-dd80fc0f |
| 8458 | Bulk Product 00615537 | Clothing | $242.92 | 398 | ★ 1.9 | 34 | BULK-0f6c10f1 |
| 8459 | Bulk Product 237e4e5b | Toys & Games | $239.14 | 251 | ★ 3.9 | 79 | BULK-23ed68f9 |
// 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
};
}