Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 12910 | Bulk Product 19d73b7d | Books | $184.45 | 256 | ★ 3.3 | 98 | BULK-61bd8e9e |
| 12911 | Bulk Product 5fbaed30 | Clothing | $740.17 | 366 | ★ 2.2 | 12 | BULK-26c11ba8 |
| 12912 | Bulk Product 86898a07 | Home & Garden | $874.76 | 36 | ★ 3.8 | 81 | BULK-221a15b9 |
| 12913 | Bulk Product 71ec8631 | Toys & Games | $346.53 | 499 | ★ 1.4 | 38 | BULK-091ee728 |
| 12914 | Bulk Product f528d9ed | Electronics | $907.19 | 180 | ★ 4.1 | 51 | BULK-9ed91cfc |
| 12915 | Bulk Product 74e17ac7 | Electronics | $455.75 | 108 | ★ 0.3 | 28 | BULK-b6c43538 |
| 12916 | Bulk Product 06ad61cf | Clothing | $492.53 | 189 | ★ 3.4 | 63 | BULK-95e66561 |
| 12917 | Bulk Product 90f9b432 | Books | $971.35 | 218 | ★ 2.3 | 8 | BULK-be7c7fa6 |
| 12918 | Bulk Product f883d3fd | Clothing | $930.89 | 159 | ★ 3.3 | 6 | BULK-f42b90f6 |
| 12919 | Bulk Product dec39d3d | Clothing | $220.52 | 331 | ★ 1.0 | 54 | BULK-c65ed877 |
| 12920 | Bulk Product 2171b0cc | Sports & Outdoors | $150.10 | 237 | ★ 1.0 | 82 | BULK-6d7ab3f7 |
| 12921 | Bulk Product 08b82a74 | Toys & Games | $302.43 | 209 | ★ 4.7 | 85 | BULK-8b407736 |
| 12922 | Bulk Product fcb5f1d1 | Books | $141.21 | 439 | ★ 4.8 | 74 | BULK-986b4295 |
| 12923 | Bulk Product dc115f1a | Sports & Outdoors | $620.35 | 156 | ★ 3.5 | 24 | BULK-effd8413 |
| 12924 | Bulk Product b3031f1d | Home & Garden | $364.67 | 402 | ★ 2.0 | 53 | BULK-459399a5 |
| 12925 | Bulk Product 533c363b | Electronics | $177.07 | 274 | ★ 2.8 | 57 | BULK-4f489af4 |
| 12926 | Bulk Product 294309bc | Clothing | $65.40 | 176 | ★ 3.7 | 24 | BULK-e3932022 |
| 12927 | Bulk Product 7f4144d0 | Toys & Games | $536.01 | 238 | ★ 2.8 | 92 | BULK-916e280a |
| 12928 | Bulk Product 2ff6c59f | Electronics | $728.10 | 252 | ★ 3.8 | 83 | BULK-4497457f |
| 12929 | Bulk Product 5a0542eb | Home & Garden | $778.46 | 488 | ★ 0.2 | 48 | BULK-10d4f3a2 |
| 12930 | Bulk Product 2f86d1a7 | Books | $135.15 | 451 | ★ 1.1 | 44 | BULK-e61800b4 |
| 12931 | Bulk Product bd82d4a3 | Sports & Outdoors | $459.71 | 437 | ★ 1.2 | 15 | BULK-7302b039 |
| 12932 | Bulk Product 9e5159b3 | Clothing | $871.60 | 492 | ★ 1.6 | 13 | BULK-4824fb64 |
| 12933 | Bulk Product d177a4cc | Books | $19.96 | 478 | ★ 3.8 | 22 | BULK-f991bf38 |
| 12934 | Bulk Product 694bdf6a | Electronics | $981.11 | 207 | ★ 2.8 | 24 | BULK-3dfb0fc0 |
| 12935 | Bulk Product 1f80c086 | Toys & Games | $716.23 | 318 | ★ 3.9 | 61 | BULK-ee850704 |
| 12936 | Bulk Product ec726240 | Home & Garden | $898.78 | 404 | ★ 2.6 | 77 | BULK-91660cb9 |
| 12937 | Bulk Product f10a6700 | Clothing | $529.12 | 243 | ★ 0.0 | 55 | BULK-c4d983ce |
| 12938 | Bulk Product 35c1e1c6 | Electronics | $997.57 | 185 | ★ 2.8 | 37 | BULK-43377687 |
| 12939 | Bulk Product e7bfc549 | Clothing | $132.69 | 450 | ★ 2.3 | 48 | BULK-ea300715 |
| 12940 | Bulk Product e10cefbb | Toys & Games | $409.01 | 316 | ★ 1.6 | 92 | BULK-ddc7c169 |
| 12941 | Bulk Product cc4436e1 | Clothing | $506.07 | 434 | ★ 2.6 | 73 | BULK-d6dc3f3f |
| 12942 | Bulk Product f831c4b0 | Home & Garden | $349.40 | 274 | ★ 2.1 | 63 | BULK-fe4d12fd |
| 12943 | Bulk Product 790829cc | Sports & Outdoors | $555.98 | 358 | ★ 3.1 | 63 | BULK-10aaf25a |
| 12944 | Bulk Product 66b2bc5c | Home & Garden | $826.82 | 284 | ★ 1.4 | 69 | BULK-24428305 |
| 12945 | Bulk Product a12b164c | Clothing | $418.99 | 356 | ★ 1.0 | 83 | BULK-99a77360 |
| 12946 | Bulk Product 4a110e87 | Books | $429.53 | 419 | ★ 4.8 | 14 | BULK-4bf1735c |
| 12947 | Bulk Product 3a29bf7b | Clothing | $401.07 | 148 | ★ 3.8 | 21 | BULK-7fc55d2b |
| 12948 | Bulk Product 07895b70 | Clothing | $953.24 | 92 | ★ 0.2 | 55 | BULK-4960ecd6 |
| 12949 | Bulk Product e3dc1396 | Books | $538.90 | 218 | ★ 1.9 | 3 | BULK-a54573e2 |
| 12950 | Bulk Product 907f8cbf | Sports & Outdoors | $250.41 | 269 | ★ 0.5 | 94 | BULK-843ead1b |
| 12951 | Bulk Product 0fbc226f | Home & Garden | $857.56 | 111 | ★ 2.9 | 42 | BULK-c17fdc21 |
| 12952 | Bulk Product 56c8e82c | Electronics | $583.89 | 32 | ★ 4.1 | 41 | BULK-dd3a5487 |
| 12953 | Bulk Product 510cd3a2 | Sports & Outdoors | $66.50 | 491 | ★ 2.3 | 46 | BULK-e3efb3c5 |
| 12954 | Bulk Product 9c675c93 | Home & Garden | $867.38 | 11 | ★ 1.8 | 22 | BULK-d9718704 |
| 12955 | Bulk Product 5d5aca00 | Toys & Games | $160.56 | 105 | ★ 2.7 | 31 | BULK-2eb8b18d |
| 12956 | Bulk Product d97ed136 | Books | $841.18 | 210 | ★ 3.0 | 73 | BULK-0e69ee1c |
| 12957 | Bulk Product 3c560e93 | Electronics | $327.22 | 152 | ★ 4.4 | 15 | BULK-62c4ace3 |
| 12958 | Bulk Product 147c262b | Clothing | $854.16 | 347 | ★ 3.9 | 65 | BULK-eb15bab3 |
| 12959 | Bulk Product 24317f01 | Toys & Games | $408.50 | 209 | ★ 1.6 | 39 | BULK-bdd0057e |
// 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
};
}