Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 17560 | Bulk Product 9d6e0c2c | Sports & Outdoors | $420.35 | 47 | ★ 3.7 | 60 | BULK-49b433db |
| 17561 | Bulk Product 0243570c | Toys & Games | $694.81 | 195 | ★ 1.5 | 7 | BULK-8ae88a7d |
| 17562 | Bulk Product 9a999498 | Home & Garden | $50.89 | 331 | ★ 2.4 | 85 | BULK-4661f6c6 |
| 17563 | Bulk Product 2feb9edf | Sports & Outdoors | $416.14 | 407 | ★ 3.4 | 18 | BULK-f6ab22dc |
| 17564 | Bulk Product f7491a91 | Sports & Outdoors | $863.97 | 230 | ★ 0.8 | 78 | BULK-1b296a6e |
| 17565 | Bulk Product d9dc0f62 | Clothing | $71.62 | 467 | ★ 1.5 | 7 | BULK-ee78e7f2 |
| 17566 | Bulk Product 97c163d6 | Books | $632.92 | 223 | ★ 0.9 | 37 | BULK-1c33315b |
| 17567 | Bulk Product 76300309 | Books | $22.91 | 322 | ★ 1.1 | 81 | BULK-9bc9ba3d |
| 17568 | Bulk Product 18cd5e8c | Clothing | $361.23 | 250 | ★ 2.0 | 41 | BULK-abb3359f |
| 17569 | Bulk Product 8b362a8b | Toys & Games | $242.23 | 32 | ★ 4.5 | 11 | BULK-4e17636f |
| 17570 | Bulk Product 12142a71 | Sports & Outdoors | $389.56 | 322 | ★ 2.6 | 32 | BULK-5fe720eb |
| 17571 | Bulk Product fe6da4fa | Clothing | $113.75 | 82 | ★ 1.1 | 47 | BULK-c9f36a3b |
| 17572 | Bulk Product 6cc64c05 | Toys & Games | $209.52 | 107 | ★ 3.1 | 14 | BULK-42612ca5 |
| 17573 | Bulk Product 9f520705 | Sports & Outdoors | $340.28 | 158 | ★ 2.6 | 2 | BULK-557c335d |
| 17574 | Bulk Product 310443d3 | Toys & Games | $114.79 | 493 | ★ 3.6 | 84 | BULK-d3e323cc |
| 17575 | Bulk Product 289e0d7d | Clothing | $421.79 | 214 | ★ 2.9 | 36 | BULK-1b6a6b59 |
| 17576 | Bulk Product ceea3b72 | Books | $392.04 | 383 | ★ 4.4 | 93 | BULK-b05a80cc |
| 17577 | Bulk Product ae68207e | Books | $336.92 | 171 | ★ 2.8 | 33 | BULK-a3cdd959 |
| 17578 | Bulk Product 2a37ee60 | Home & Garden | $594.19 | 250 | ★ 2.1 | 33 | BULK-d6482343 |
| 17579 | Bulk Product cda3c2b4 | Clothing | $553.41 | 143 | ★ 1.5 | 58 | BULK-e568dcd6 |
| 17580 | Bulk Product 2f6455bc | Books | $587.40 | 8 | ★ 4.4 | 4 | BULK-a65a772b |
| 17581 | Bulk Product fd05f85a | Home & Garden | $583.81 | 475 | ★ 2.9 | 26 | BULK-d38f774e |
| 17582 | Bulk Product dcaf155e | Toys & Games | $198.41 | 301 | ★ 2.1 | 42 | BULK-4899eace |
| 17583 | Bulk Product 2b083628 | Sports & Outdoors | $914.05 | 372 | ★ 4.2 | 98 | BULK-9b9898bd |
| 17584 | Bulk Product ce66926b | Electronics | $636.47 | 41 | ★ 2.9 | 45 | BULK-6e0b07c8 |
| 17585 | Bulk Product f9eddf9e | Electronics | $506.72 | 174 | ★ 1.2 | 20 | BULK-2cf819d8 |
| 17586 | Bulk Product f9340264 | Sports & Outdoors | $803.68 | 486 | ★ 2.1 | 82 | BULK-e569fc5c |
| 17587 | Bulk Product 3817ef9b | Sports & Outdoors | $232.79 | 207 | ★ 3.9 | 64 | BULK-29ea3ec5 |
| 17588 | Bulk Product 4b9b5a8d | Home & Garden | $396.06 | 213 | ★ 2.6 | 25 | BULK-d003ea61 |
| 17589 | Bulk Product 2972081e | Clothing | $239.52 | 481 | ★ 2.4 | 26 | BULK-7ab2fc07 |
| 17590 | Bulk Product 06325cd1 | Clothing | $620.35 | 475 | ★ 1.4 | 44 | BULK-46cbb968 |
| 17591 | Bulk Product 50c837e6 | Electronics | $228.48 | 115 | ★ 4.5 | 85 | BULK-76fcf34d |
| 17592 | Bulk Product a5848cf7 | Clothing | $84.67 | 316 | ★ 3.1 | 7 | BULK-ef92a106 |
| 17593 | Bulk Product b7276cd4 | Sports & Outdoors | $885.95 | 356 | ★ 0.1 | 13 | BULK-42d66e73 |
| 17594 | Bulk Product 67bab908 | Sports & Outdoors | $78.55 | 316 | ★ 0.1 | 16 | BULK-a70ca7d8 |
| 17595 | Bulk Product 1f308b60 | Clothing | $731.92 | 92 | ★ 2.5 | 43 | BULK-75d1e7c0 |
| 17596 | Bulk Product f0ce9a53 | Electronics | $64.61 | 430 | ★ 2.5 | 98 | BULK-7df1e2b9 |
| 17597 | Bulk Product 3a46844b | Electronics | $851.71 | 6 | ★ 2.5 | 92 | BULK-2a1b69a6 |
| 17598 | Bulk Product 13ec7338 | Clothing | $709.86 | 22 | ★ 1.2 | 22 | BULK-6d66461b |
| 17599 | Bulk Product e6831e7f | Home & Garden | $757.36 | 153 | ★ 4.2 | 91 | BULK-582390ae |
| 17600 | Bulk Product 9099d96a | Books | $327.74 | 30 | ★ 0.5 | 7 | BULK-73a3f822 |
| 17601 | Bulk Product d2f8685d | Sports & Outdoors | $434.84 | 315 | ★ 4.4 | 45 | BULK-956450de |
| 17602 | Bulk Product 80d1a443 | Electronics | $930.19 | 420 | ★ 3.8 | 4 | BULK-f5d9c238 |
| 17603 | Bulk Product bdfe006e | Books | $24.17 | 457 | ★ 3.6 | 81 | BULK-07226e83 |
| 17604 | Bulk Product 478c5a19 | Clothing | $34.20 | 175 | ★ 2.9 | 66 | BULK-3bff4fbb |
| 17605 | Bulk Product 99bd199c | Home & Garden | $550.16 | 305 | ★ 3.6 | 66 | BULK-0a3ee932 |
| 17606 | Bulk Product 430a56a7 | Clothing | $312.53 | 187 | ★ 0.1 | 65 | BULK-9e4a62f1 |
| 17607 | Bulk Product b775199f | Home & Garden | $63.42 | 245 | ★ 2.1 | 67 | BULK-104ab582 |
| 17608 | Bulk Product 265e7051 | Books | $260.70 | 275 | ★ 0.5 | 85 | BULK-5b1f24ed |
| 17609 | Bulk Product 18f6b4aa | Home & Garden | $511.87 | 48 | ★ 3.5 | 16 | BULK-99aa67f3 |
// 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
};
}