Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 10710 | Bulk Product 4ed74006 | Electronics | $165.35 | 152 | ★ 1.3 | 7 | BULK-217000c5 |
| 10711 | Bulk Product 1c78fe15 | Books | $435.17 | 36 | ★ 3.7 | 74 | BULK-68040256 |
| 10712 | Bulk Product 6a9582e8 | Toys & Games | $260.79 | 300 | ★ 4.0 | 59 | BULK-eef24bd0 |
| 10713 | Bulk Product c4da1497 | Sports & Outdoors | $685.96 | 368 | ★ 4.3 | 49 | BULK-41042761 |
| 10714 | Bulk Product 7d4756ef | Home & Garden | $466.59 | 31 | ★ 2.1 | 0 | BULK-cb6e9410 |
| 10715 | Bulk Product 1aadb633 | Books | $737.30 | 104 | ★ 3.3 | 21 | BULK-8896fa8e |
| 10716 | Bulk Product ff183b2c | Clothing | $105.52 | 400 | ★ 1.3 | 76 | BULK-21e1851d |
| 10717 | Bulk Product 1025dcb4 | Books | $337.73 | 134 | ★ 3.5 | 11 | BULK-1ed57204 |
| 10718 | Bulk Product e5c03d19 | Sports & Outdoors | $1,001.55 | 241 | ★ 1.7 | 0 | BULK-1d6831f7 |
| 10719 | Bulk Product e4042a53 | Home & Garden | $966.12 | 248 | ★ 1.5 | 61 | BULK-6be56c3d |
| 10720 | Bulk Product 8cf72086 | Toys & Games | $26.57 | 182 | ★ 4.4 | 54 | BULK-818619cc |
| 10721 | Bulk Product 42505b27 | Clothing | $872.32 | 139 | ★ 2.1 | 74 | BULK-cc6d70c5 |
| 10722 | Bulk Product 51c669e2 | Electronics | $234.94 | 429 | ★ 2.6 | 54 | BULK-fb3efb31 |
| 10723 | Bulk Product 47017ff0 | Toys & Games | $479.71 | 127 | ★ 4.5 | 10 | BULK-96ef93c2 |
| 10724 | Bulk Product 1db8eff4 | Toys & Games | $889.65 | 294 | ★ 4.9 | 69 | BULK-952917aa |
| 10725 | Bulk Product da8de844 | Electronics | $537.87 | 332 | ★ 4.2 | 83 | BULK-6e11481a |
| 10726 | Bulk Product b27318d1 | Clothing | $988.01 | 456 | ★ 0.2 | 6 | BULK-8b101070 |
| 10727 | Bulk Product 20577a1b | Clothing | $358.02 | 92 | ★ 4.4 | 30 | BULK-ef317ed2 |
| 10728 | Bulk Product 977efce7 | Toys & Games | $748.02 | 308 | ★ 0.6 | 36 | BULK-3a69a0bc |
| 10729 | Bulk Product 8fabdb4c | Home & Garden | $641.60 | 478 | ★ 0.6 | 30 | BULK-9f521bb2 |
| 10730 | Bulk Product d4fe605a | Toys & Games | $715.01 | 138 | ★ 1.5 | 12 | BULK-1b360803 |
| 10731 | Bulk Product e67bd565 | Home & Garden | $290.88 | 345 | ★ 4.3 | 92 | BULK-89dbbfaf |
| 10732 | Bulk Product 0726d733 | Electronics | $405.65 | 454 | ★ 3.4 | 29 | BULK-a8248b3d |
| 10733 | Bulk Product f0e9b2b0 | Toys & Games | $619.29 | 291 | ★ 4.0 | 57 | BULK-94de391d |
| 10734 | Bulk Product a727073a | Books | $577.63 | 306 | ★ 4.9 | 66 | BULK-b9877d65 |
| 10735 | Bulk Product 46979eef | Books | $951.56 | 471 | ★ 0.9 | 46 | BULK-1fce9f33 |
| 10736 | Bulk Product b84d3cbc | Sports & Outdoors | $186.92 | 59 | ★ 3.3 | 44 | BULK-9ef2b6f6 |
| 10737 | Bulk Product eff31ad0 | Electronics | $124.90 | 481 | ★ 3.4 | 81 | BULK-d691d484 |
| 10738 | Bulk Product 3f511151 | Sports & Outdoors | $127.14 | 349 | ★ 0.5 | 69 | BULK-5c6b5ba9 |
| 10739 | Bulk Product d0b8f28f | Home & Garden | $375.04 | 270 | ★ 4.9 | 70 | BULK-26802606 |
| 10740 | Bulk Product 9af5c70a | Toys & Games | $545.35 | 258 | ★ 4.8 | 9 | BULK-cf75728b |
| 10741 | Bulk Product 1671c14b | Sports & Outdoors | $256.50 | 497 | ★ 4.7 | 18 | BULK-c146618f |
| 10742 | Bulk Product c2ea06e5 | Sports & Outdoors | $152.77 | 91 | ★ 3.5 | 6 | BULK-7f2410ee |
| 10743 | Bulk Product 4ff19b15 | Clothing | $963.94 | 386 | ★ 3.8 | 46 | BULK-e8369ed0 |
| 10744 | Bulk Product 3aee2ac9 | Home & Garden | $717.26 | 357 | ★ 0.4 | 69 | BULK-89cca0d1 |
| 10745 | Bulk Product d5ef0d8d | Electronics | $491.04 | 495 | ★ 3.4 | 21 | BULK-cd9919f1 |
| 10746 | Bulk Product d58e2467 | Electronics | $534.53 | 100 | ★ 2.8 | 43 | BULK-25f027a5 |
| 10747 | Bulk Product 060d4d25 | Sports & Outdoors | $44.99 | 459 | ★ 3.4 | 90 | BULK-1ee4be51 |
| 10748 | Bulk Product 6f4c4e22 | Electronics | $443.51 | 15 | ★ 1.5 | 49 | BULK-a00c9d5e |
| 10749 | Bulk Product 4ccfe903 | Electronics | $360.14 | 264 | ★ 2.7 | 38 | BULK-da157509 |
| 10750 | Bulk Product e12d2129 | Home & Garden | $525.53 | 231 | ★ 4.8 | 57 | BULK-0d39684f |
| 10751 | Bulk Product 0e45445d | Electronics | $199.37 | 100 | ★ 1.9 | 17 | BULK-45993b6a |
| 10752 | Bulk Product 3b14cd45 | Toys & Games | $422.36 | 402 | ★ 4.4 | 88 | BULK-5648ab5a |
| 10753 | Bulk Product fde9ed2c | Toys & Games | $11.87 | 171 | ★ 1.8 | 21 | BULK-269a2bcb |
| 10754 | Bulk Product 30db0342 | Clothing | $713.97 | 49 | ★ 1.5 | 80 | BULK-69b0897f |
| 10755 | Bulk Product 3ee82875 | Toys & Games | $79.09 | 407 | ★ 4.2 | 81 | BULK-815228a2 |
| 10756 | Bulk Product 9bcccc2a | Books | $410.74 | 484 | ★ 2.7 | 78 | BULK-a2ff971a |
| 10757 | Bulk Product d25681c9 | Toys & Games | $165.55 | 46 | ★ 2.5 | 35 | BULK-5c65ff8b |
| 10758 | Bulk Product 959b0c09 | Sports & Outdoors | $515.06 | 34 | ★ 3.2 | 71 | BULK-c87475a2 |
| 10759 | Bulk Product 1189022f | Toys & Games | $498.63 | 437 | ★ 3.1 | 63 | BULK-62a8b6f6 |
// 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
};
}