Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 9960 | Bulk Product be0aae2f | Toys & Games | $627.29 | 411 | ★ 3.4 | 54 | BULK-09a2eb82 |
| 9961 | Bulk Product 8bca77bd | Electronics | $474.96 | 48 | ★ 4.5 | 22 | BULK-ae5ae77f |
| 9962 | Bulk Product 525a1b16 | Clothing | $602.99 | 138 | ★ 4.0 | 69 | BULK-1149c84b |
| 9963 | Bulk Product 4e2c0a7f | Home & Garden | $610.78 | 468 | ★ 0.4 | 52 | BULK-e383b74f |
| 9964 | Bulk Product c8f93528 | Sports & Outdoors | $699.10 | 304 | ★ 0.1 | 65 | BULK-91e78ace |
| 9965 | Bulk Product 9558669e | Electronics | $63.85 | 478 | ★ 1.1 | 56 | BULK-84b3d669 |
| 9966 | Bulk Product f43d150c | Sports & Outdoors | $45.69 | 485 | ★ 0.3 | 7 | BULK-4cc44020 |
| 9967 | Bulk Product ce185969 | Home & Garden | $868.75 | 150 | ★ 2.5 | 73 | BULK-8a4d1668 |
| 9968 | Bulk Product b1250be8 | Home & Garden | $963.59 | 189 | ★ 3.8 | 94 | BULK-2d6886a1 |
| 9969 | Bulk Product c99816b1 | Electronics | $681.37 | 178 | ★ 3.3 | 15 | BULK-e355d86a |
| 9970 | Bulk Product 2b9aa4d7 | Books | $249.50 | 399 | ★ 4.8 | 46 | BULK-2487b0e3 |
| 9971 | Bulk Product 6e5b5fae | Sports & Outdoors | $320.58 | 445 | ★ 4.8 | 78 | BULK-0fb6310d |
| 9972 | Bulk Product d4d21444 | Toys & Games | $311.26 | 31 | ★ 1.4 | 18 | BULK-9153d6fa |
| 9973 | Bulk Product bb6c45fd | Toys & Games | $417.25 | 90 | ★ 2.2 | 44 | BULK-942c22aa |
| 9974 | Bulk Product 1eea8999 | Electronics | $234.64 | 177 | ★ 1.5 | 9 | BULK-c133b005 |
| 9975 | Bulk Product 77edc7ec | Electronics | $50.92 | 262 | ★ 3.9 | 52 | BULK-9d2559ff |
| 9976 | Bulk Product e2512b00 | Toys & Games | $122.00 | 177 | ★ 2.5 | 54 | BULK-7b1d1d9d |
| 9977 | Bulk Product 225b566b | Books | $197.78 | 347 | ★ 2.5 | 24 | BULK-8043c7f4 |
| 9978 | Bulk Product e5002e63 | Electronics | $207.29 | 125 | ★ 3.2 | 13 | BULK-fc5321fa |
| 9979 | Bulk Product d2559771 | Clothing | $254.53 | 97 | ★ 2.6 | 48 | BULK-7fcf6142 |
| 9980 | Bulk Product 6a6981be | Clothing | $862.44 | 457 | ★ 1.3 | 37 | BULK-672c0ec9 |
| 9981 | Bulk Product ac4e4d61 | Home & Garden | $314.38 | 460 | ★ 2.2 | 73 | BULK-ce4269b0 |
| 9982 | Bulk Product 2a94ae1f | Sports & Outdoors | $949.58 | 417 | ★ 3.9 | 62 | BULK-e707e8ce |
| 9983 | Bulk Product e97d7361 | Clothing | $247.25 | 235 | ★ 0.9 | 62 | BULK-c3278791 |
| 9984 | Bulk Product d21ea123 | Clothing | $659.82 | 41 | ★ 2.1 | 85 | BULK-e268e116 |
| 9985 | Bulk Product dc382fa1 | Electronics | $293.14 | 143 | ★ 1.9 | 86 | BULK-9707f128 |
| 9986 | Bulk Product 79640e02 | Books | $885.06 | 45 | ★ 1.0 | 95 | BULK-cf9d5c62 |
| 9987 | Bulk Product 18115f8a | Sports & Outdoors | $348.43 | 192 | ★ 2.4 | 47 | BULK-70c85eac |
| 9988 | Bulk Product fc7941b5 | Sports & Outdoors | $823.78 | 327 | ★ 4.6 | 7 | BULK-d02c97bc |
| 9989 | Bulk Product 1b10038f | Home & Garden | $83.04 | 393 | ★ 0.7 | 31 | BULK-1b74a33a |
| 9990 | Bulk Product 2acee5f6 | Clothing | $569.08 | 231 | ★ 0.7 | 27 | BULK-33c7e0da |
| 9991 | Bulk Product e2ea7e3a | Clothing | $626.70 | 301 | ★ 2.4 | 98 | BULK-d7b7f67f |
| 9992 | Bulk Product b8009ef2 | Electronics | $326.29 | 279 | ★ 3.8 | 34 | BULK-6fbf8ba3 |
| 9993 | Bulk Product f1fc2a6b | Clothing | $63.49 | 420 | ★ 4.2 | 28 | BULK-8a9f63e5 |
| 9994 | Bulk Product aa1bc554 | Sports & Outdoors | $444.47 | 384 | ★ 1.6 | 35 | BULK-0d692e6c |
| 9995 | Bulk Product ab255868 | Electronics | $981.05 | 132 | ★ 2.9 | 10 | BULK-be862a59 |
| 9996 | Bulk Product c15b05c2 | Books | $79.29 | 309 | ★ 0.9 | 24 | BULK-752a1ffb |
| 9997 | Bulk Product c2ec3ec3 | Home & Garden | $502.61 | 77 | ★ 2.7 | 91 | BULK-5d9d65b0 |
| 9998 | Bulk Product 0b9a6868 | Books | $495.15 | 263 | ★ 3.4 | 11 | BULK-3e5da8fb |
| 9999 | Bulk Product a61343f7 | Books | $243.20 | 345 | ★ 3.6 | 83 | BULK-4422502a |
| 10000 | Bulk Product ae6abbe0 | Books | $947.36 | 76 | ★ 3.7 | 84 | BULK-90f0215c |
| 10001 | Bulk Product f99f579b | Books | $309.82 | 339 | ★ 2.2 | 49 | BULK-3815e7fb |
| 10002 | Bulk Product 96803d16 | Books | $634.87 | 475 | ★ 1.7 | 29 | BULK-d3e0e37b |
| 10003 | Bulk Product f8ba144d | Electronics | $338.09 | 56 | ★ 0.7 | 66 | BULK-c9ed3998 |
| 10004 | Bulk Product 3337bfcb | Toys & Games | $737.23 | 305 | ★ 1.0 | 32 | BULK-ef0bb3d1 |
| 10005 | Bulk Product f8714db6 | Electronics | $491.19 | 101 | ★ 2.2 | 97 | BULK-a417df15 |
| 10006 | Bulk Product 65a573a9 | Toys & Games | $875.89 | 128 | ★ 2.8 | 56 | BULK-7c0dd7cd |
| 10007 | Bulk Product 40176488 | Clothing | $597.36 | 164 | ★ 1.2 | 40 | BULK-79ef070b |
| 10008 | Bulk Product 1231e689 | Electronics | $696.42 | 230 | ★ 2.8 | 97 | BULK-2d60a73f |
| 10009 | Bulk Product aef04d60 | Toys & Games | $952.73 | 487 | ★ 1.6 | 98 | BULK-0dd3d5da |
// 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
};
}