Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 21610 | Bulk Product 638134c2 | Clothing | $464.03 | 102 | ★ 2.8 | 68 | BULK-59557243 |
| 21611 | Bulk Product 3fa347a3 | Home & Garden | $720.47 | 388 | ★ 4.9 | 0 | BULK-5debe2df |
| 21612 | Bulk Product b7ad9adc | Electronics | $787.88 | 23 | ★ 4.2 | 67 | BULK-1daa7401 |
| 21613 | Bulk Product a73e98f0 | Clothing | $969.53 | 164 | ★ 0.2 | 47 | BULK-a5cd7aa3 |
| 21614 | Bulk Product 54edd1bf | Home & Garden | $322.97 | 429 | ★ 2.2 | 1 | BULK-7791664d |
| 21615 | Bulk Product 15ca850f | Toys & Games | $637.59 | 455 | ★ 3.3 | 2 | BULK-0be02946 |
| 21616 | Bulk Product 8f7b60f6 | Sports & Outdoors | $358.83 | 50 | ★ 0.9 | 67 | BULK-41eeef7e |
| 21617 | Bulk Product 2ca1655e | Books | $397.72 | 437 | ★ 1.3 | 74 | BULK-0299b133 |
| 21618 | Bulk Product be3bd040 | Clothing | $627.99 | 212 | ★ 2.2 | 45 | BULK-8c770936 |
| 21619 | Bulk Product 60bc0339 | Electronics | $469.57 | 350 | ★ 3.6 | 1 | BULK-f1ba9b08 |
| 21620 | Bulk Product 7e6eee19 | Books | $121.90 | 268 | ★ 3.1 | 94 | BULK-ec9f748c |
| 21621 | Bulk Product ea408054 | Books | $742.71 | 122 | ★ 2.3 | 18 | BULK-5dde7762 |
| 21622 | Bulk Product 005668b1 | Toys & Games | $372.40 | 239 | ★ 3.4 | 19 | BULK-eb655def |
| 21623 | Bulk Product ae82a4ee | Books | $888.46 | 192 | ★ 2.4 | 64 | BULK-77cca73d |
| 21624 | Bulk Product a1d5e382 | Sports & Outdoors | $907.24 | 181 | ★ 2.2 | 17 | BULK-36019cdb |
| 21625 | Bulk Product 4cdf8305 | Sports & Outdoors | $941.82 | 485 | ★ 3.0 | 48 | BULK-7e9fdc4e |
| 21626 | Bulk Product 9a11192d | Home & Garden | $191.44 | 201 | ★ 1.8 | 65 | BULK-a707ca39 |
| 21627 | Bulk Product 1f929491 | Clothing | $319.38 | 27 | ★ 2.5 | 30 | BULK-8ef4f813 |
| 21628 | Bulk Product f7a2e3e9 | Clothing | $370.08 | 31 | ★ 0.3 | 70 | BULK-9b828b5d |
| 21629 | Bulk Product 8976cd39 | Home & Garden | $952.50 | 153 | ★ 0.2 | 18 | BULK-dc1dcb64 |
| 21630 | Bulk Product 41cb4a9f | Sports & Outdoors | $320.38 | 144 | ★ 4.2 | 75 | BULK-9c0bd3eb |
| 21631 | Bulk Product cf10bb83 | Sports & Outdoors | $271.21 | 117 | ★ 3.2 | 72 | BULK-183e3fd0 |
| 21632 | Bulk Product d13c7048 | Toys & Games | $53.98 | 465 | ★ 1.9 | 51 | BULK-43facc30 |
| 21633 | Bulk Product 93739619 | Clothing | $973.83 | 331 | ★ 2.5 | 55 | BULK-e7141fbc |
| 21634 | Bulk Product 43c47ab7 | Electronics | $116.22 | 443 | ★ 3.0 | 15 | BULK-5209e42c |
| 21635 | Bulk Product 61b82cb9 | Home & Garden | $146.05 | 246 | ★ 4.7 | 71 | BULK-1da208e4 |
| 21636 | Bulk Product 929ef052 | Clothing | $906.68 | 298 | ★ 4.1 | 20 | BULK-43e772d9 |
| 21637 | Bulk Product 881e687f | Clothing | $684.31 | 141 | ★ 1.4 | 5 | BULK-c25e6416 |
| 21638 | Bulk Product 68209024 | Electronics | $801.66 | 191 | ★ 4.0 | 46 | BULK-88625820 |
| 21639 | Bulk Product 47f5de1c | Home & Garden | $174.36 | 422 | ★ 0.2 | 94 | BULK-0b5c15db |
| 21640 | Bulk Product ea28a759 | Toys & Games | $261.28 | 424 | ★ 0.5 | 42 | BULK-6fb1aefa |
| 21641 | Bulk Product f1c3c2d8 | Clothing | $662.80 | 102 | ★ 2.7 | 70 | BULK-24696f1b |
| 21642 | Bulk Product 2df9c51c | Clothing | $107.33 | 290 | ★ 4.0 | 67 | BULK-1441f566 |
| 21643 | Bulk Product 3193008d | Sports & Outdoors | $729.40 | 152 | ★ 1.7 | 98 | BULK-536e8320 |
| 21644 | Bulk Product d0840a43 | Toys & Games | $58.67 | 347 | ★ 0.4 | 7 | BULK-a7c52e21 |
| 21645 | Bulk Product 3c102a50 | Sports & Outdoors | $780.09 | 346 | ★ 3.5 | 65 | BULK-a027a2d1 |
| 21646 | Bulk Product 6b2c949d | Books | $976.56 | 137 | ★ 3.3 | 44 | BULK-7b04197e |
| 21647 | Bulk Product 5ada33d9 | Electronics | $343.43 | 407 | ★ 1.0 | 36 | BULK-4c21759b |
| 21648 | Bulk Product e7ec6076 | Sports & Outdoors | $518.65 | 281 | ★ 2.6 | 67 | BULK-b0685ba9 |
| 21649 | Bulk Product 387252f9 | Books | $941.23 | 39 | ★ 4.0 | 59 | BULK-a1d1d00f |
| 21650 | Bulk Product 45efd838 | Toys & Games | $759.80 | 395 | ★ 2.9 | 98 | BULK-2736d301 |
| 21651 | Bulk Product 4c262981 | Toys & Games | $418.15 | 8 | ★ 3.5 | 43 | BULK-ffc564e4 |
| 21652 | Bulk Product b827fbfa | Home & Garden | $326.34 | 334 | ★ 0.8 | 71 | BULK-01cfa29d |
| 21653 | Bulk Product c084ed85 | Clothing | $221.47 | 234 | ★ 3.1 | 93 | BULK-2a1c570f |
| 21654 | Bulk Product c8544cf3 | Home & Garden | $586.45 | 200 | ★ 1.9 | 76 | BULK-89aeb15e |
| 21655 | Bulk Product c64f0439 | Toys & Games | $644.57 | 236 | ★ 4.7 | 84 | BULK-f87495de |
| 21656 | Bulk Product eda9b9a1 | Clothing | $378.09 | 171 | ★ 4.4 | 81 | BULK-310e6bd1 |
| 21657 | Bulk Product 21817395 | Electronics | $507.91 | 331 | ★ 0.8 | 71 | BULK-d988b40c |
| 21658 | Bulk Product 5462ed73 | Toys & Games | $171.79 | 475 | ★ 1.3 | 56 | BULK-7e49e80d |
| 21659 | Bulk Product 2a66c999 | Books | $414.52 | 171 | ★ 2.4 | 54 | BULK-347deddc |
// 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
};
}