Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 22610 | Bulk Product 2c987b55 | Clothing | $404.24 | 256 | ★ 4.1 | 98 | BULK-1bbb2ede |
| 22611 | Bulk Product 574e8e46 | Sports & Outdoors | $176.89 | 251 | ★ 2.1 | 93 | BULK-f5b9c41c |
| 22612 | Bulk Product 5b8bd3d1 | Electronics | $583.64 | 83 | ★ 3.6 | 48 | BULK-603a637b |
| 22613 | Bulk Product 2c4e9da8 | Sports & Outdoors | $233.33 | 293 | ★ 2.5 | 23 | BULK-661cc044 |
| 22614 | Bulk Product d1ec361e | Books | $152.83 | 392 | ★ 4.6 | 31 | BULK-51452312 |
| 22615 | Bulk Product 14d07614 | Clothing | $716.68 | 218 | ★ 0.4 | 80 | BULK-8e13949e |
| 22616 | Bulk Product 8913bae9 | Books | $749.92 | 407 | ★ 2.0 | 14 | BULK-4691ff61 |
| 22617 | Bulk Product 44e558d1 | Toys & Games | $845.89 | 485 | ★ 5.0 | 46 | BULK-260791f4 |
| 22618 | Bulk Product c36a37e7 | Clothing | $363.90 | 29 | ★ 4.2 | 2 | BULK-2d23ebba |
| 22619 | Bulk Product 6a9ca0b5 | Books | $41.85 | 217 | ★ 1.2 | 51 | BULK-0eb60ba9 |
| 22620 | Bulk Product 8eca20a5 | Toys & Games | $577.81 | 302 | ★ 2.0 | 9 | BULK-9d6c098d |
| 22621 | Bulk Product 95df5539 | Clothing | $207.62 | 319 | ★ 4.7 | 92 | BULK-d1cb20d1 |
| 22622 | Bulk Product c495499c | Home & Garden | $630.91 | 467 | ★ 0.4 | 1 | BULK-b27522bd |
| 22623 | Bulk Product f26b622f | Clothing | $716.91 | 144 | ★ 4.0 | 98 | BULK-02cb1a82 |
| 22624 | Bulk Product 73beec33 | Home & Garden | $923.95 | 61 | ★ 3.9 | 54 | BULK-054a02e1 |
| 22625 | Bulk Product c651edd9 | Electronics | $114.74 | 391 | ★ 2.9 | 52 | BULK-2a2f2b87 |
| 22626 | Bulk Product 16b3116f | Books | $519.33 | 311 | ★ 1.3 | 26 | BULK-ab4f2002 |
| 22627 | Bulk Product 08f0cc9e | Clothing | $763.72 | 481 | ★ 4.8 | 74 | BULK-7c998eb3 |
| 22628 | Bulk Product 9231b4cc | Home & Garden | $873.35 | 284 | ★ 0.4 | 84 | BULK-6c3c648b |
| 22629 | Bulk Product b46ce615 | Books | $675.64 | 409 | ★ 3.4 | 29 | BULK-a5fe3ece |
| 22630 | Bulk Product 66d61766 | Electronics | $987.38 | 314 | ★ 3.2 | 66 | BULK-e25454ba |
| 22631 | Bulk Product b581da28 | Books | $226.32 | 115 | ★ 1.4 | 64 | BULK-539307f3 |
| 22632 | Bulk Product 6096e2c6 | Electronics | $77.73 | 468 | ★ 0.4 | 41 | BULK-b3bba3dc |
| 22633 | Bulk Product 1047c7ab | Books | $358.78 | 244 | ★ 4.8 | 64 | BULK-ab9df978 |
| 22634 | Bulk Product 4ad15146 | Electronics | $15.36 | 376 | ★ 2.9 | 68 | BULK-e04812cd |
| 22635 | Bulk Product 2f31fb38 | Books | $481.20 | 150 | ★ 2.1 | 46 | BULK-bc69d34c |
| 22636 | Bulk Product 35f83ff7 | Home & Garden | $843.70 | 97 | ★ 4.8 | 40 | BULK-09f6ab26 |
| 22637 | Bulk Product 899cde2b | Sports & Outdoors | $803.49 | 241 | ★ 1.3 | 83 | BULK-51eb4c34 |
| 22638 | Bulk Product b59feef9 | Electronics | $661.04 | 220 | ★ 2.9 | 95 | BULK-a2bc933e |
| 22639 | Bulk Product 1e7d08ff | Sports & Outdoors | $321.28 | 98 | ★ 2.1 | 50 | BULK-dee46f04 |
| 22640 | Bulk Product e7a831f0 | Home & Garden | $32.73 | 394 | ★ 3.3 | 84 | BULK-ef331a0e |
| 22641 | Bulk Product 8634f659 | Toys & Games | $506.85 | 264 | ★ 3.8 | 45 | BULK-13d1b062 |
| 22642 | Bulk Product cc777ea0 | Home & Garden | $133.28 | 10 | ★ 1.0 | 55 | BULK-51ddad6f |
| 22643 | Bulk Product 483d9231 | Clothing | $771.43 | 165 | ★ 2.0 | 85 | BULK-bc930629 |
| 22644 | Bulk Product 2b0fb81f | Clothing | $633.94 | 53 | ★ 4.6 | 77 | BULK-b47f2d8d |
| 22645 | Bulk Product 175663a3 | Home & Garden | $161.88 | 346 | ★ 5.0 | 80 | BULK-100b6f74 |
| 22646 | Bulk Product 56af5038 | Sports & Outdoors | $45.65 | 291 | ★ 3.3 | 1 | BULK-dbf96082 |
| 22647 | Bulk Product 89e4e63b | Clothing | $457.11 | 39 | ★ 4.7 | 75 | BULK-9b453ec5 |
| 22648 | Bulk Product c2a31238 | Electronics | $628.06 | 344 | ★ 2.6 | 81 | BULK-a39f13a4 |
| 22649 | Bulk Product 25b0ebd0 | Electronics | $904.28 | 243 | ★ 1.0 | 83 | BULK-d784e839 |
| 22650 | Bulk Product eeb656eb | Sports & Outdoors | $309.65 | 205 | ★ 0.7 | 7 | BULK-051270f7 |
| 22651 | Bulk Product 74b7a39f | Books | $732.83 | 476 | ★ 2.2 | 96 | BULK-6c3cf099 |
| 22652 | Bulk Product cd129e7f | Books | $228.52 | 73 | ★ 1.0 | 32 | BULK-25642b6f |
| 22653 | Bulk Product 41c91ee1 | Electronics | $114.65 | 424 | ★ 4.2 | 42 | BULK-c4eb6f75 |
| 22654 | Bulk Product 67ec3c8d | Sports & Outdoors | $918.06 | 414 | ★ 3.1 | 9 | BULK-91df5e86 |
| 22655 | Bulk Product 19d05312 | Books | $736.09 | 132 | ★ 2.5 | 43 | BULK-f8e951ae |
| 22656 | Bulk Product 76dde920 | Books | $338.69 | 406 | ★ 3.3 | 71 | BULK-1461490b |
| 22657 | Bulk Product 2bfa0fc9 | Books | $103.22 | 409 | ★ 1.2 | 45 | BULK-817218f8 |
| 22658 | Bulk Product 2f58baa8 | Sports & Outdoors | $294.75 | 354 | ★ 3.5 | 21 | BULK-ab713ffd |
| 22659 | Bulk Product 113d8ba9 | Home & Garden | $753.72 | 87 | ★ 3.7 | 13 | BULK-7e75bb4e |
// 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
};
}