Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 18910 | Bulk Product b8cb271c | Clothing | $643.30 | 470 | ★ 1.0 | 58 | BULK-7fb3799f |
| 18911 | Bulk Product 1bf49534 | Clothing | $572.48 | 407 | ★ 1.4 | 97 | BULK-aa29119f |
| 18912 | Bulk Product f3637437 | Electronics | $858.75 | 398 | ★ 1.6 | 71 | BULK-93471691 |
| 18913 | Bulk Product 4708bf27 | Books | $113.75 | 104 | ★ 2.2 | 34 | BULK-fef27990 |
| 18914 | Bulk Product 067abd82 | Books | $617.38 | 64 | ★ 4.8 | 35 | BULK-ee143b87 |
| 18915 | Bulk Product ed777da6 | Toys & Games | $453.14 | 318 | ★ 2.5 | 52 | BULK-ea095515 |
| 18916 | Bulk Product c504e0ff | Electronics | $344.95 | 3 | ★ 0.7 | 4 | BULK-95ab5794 |
| 18917 | Bulk Product 8e498695 | Electronics | $837.32 | 361 | ★ 4.4 | 45 | BULK-cc3bfda0 |
| 18918 | Bulk Product 6d9f7bf8 | Toys & Games | $459.79 | 234 | ★ 1.6 | 38 | BULK-e91df946 |
| 18919 | Bulk Product f018ff88 | Home & Garden | $280.31 | 323 | ★ 2.7 | 86 | BULK-7194047b |
| 18920 | Bulk Product d5d0937d | Electronics | $238.89 | 348 | ★ 2.0 | 35 | BULK-c8184c78 |
| 18921 | Bulk Product 645c606a | Clothing | $540.41 | 26 | ★ 0.6 | 43 | BULK-31c88759 |
| 18922 | Bulk Product 780df223 | Books | $315.31 | 269 | ★ 0.4 | 44 | BULK-2ff13a5e |
| 18923 | Bulk Product 02d818b8 | Sports & Outdoors | $874.83 | 438 | ★ 4.6 | 77 | BULK-5f78d7d6 |
| 18924 | Bulk Product d77a4d48 | Home & Garden | $463.27 | 61 | ★ 3.3 | 21 | BULK-3b884c39 |
| 18925 | Bulk Product 1af58afe | Books | $280.49 | 136 | ★ 0.3 | 80 | BULK-e6ccfb11 |
| 18926 | Bulk Product b3d4c8fa | Electronics | $927.24 | 7 | ★ 1.3 | 76 | BULK-d6caa71e |
| 18927 | Bulk Product 91342a4e | Toys & Games | $191.83 | 233 | ★ 2.9 | 28 | BULK-ceef9846 |
| 18928 | Bulk Product a8f304d3 | Books | $313.12 | 478 | ★ 2.2 | 16 | BULK-df9c5f0f |
| 18929 | Bulk Product ab19de8a | Books | $606.17 | 3 | ★ 0.2 | 98 | BULK-25fe1283 |
| 18930 | Bulk Product d7b080ee | Sports & Outdoors | $320.45 | 265 | ★ 2.2 | 20 | BULK-ff284dbb |
| 18931 | Bulk Product badfb0a1 | Toys & Games | $184.25 | 52 | ★ 2.4 | 60 | BULK-f775925b |
| 18932 | Bulk Product 2d0070ec | Sports & Outdoors | $41.21 | 233 | ★ 4.0 | 18 | BULK-c312d914 |
| 18933 | Bulk Product 0759a6d0 | Clothing | $320.41 | 326 | ★ 4.1 | 75 | BULK-53c84f2d |
| 18934 | Bulk Product 22bd012f | Electronics | $957.82 | 353 | ★ 4.5 | 24 | BULK-0b9f4bd3 |
| 18935 | Bulk Product 03f6998f | Sports & Outdoors | $169.61 | 311 | ★ 4.7 | 53 | BULK-20ab030f |
| 18936 | Bulk Product 6b87456b | Sports & Outdoors | $254.52 | 273 | ★ 3.2 | 62 | BULK-e282ab64 |
| 18937 | Bulk Product 3aeae30e | Books | $529.94 | 321 | ★ 2.3 | 34 | BULK-ac605a8a |
| 18938 | Bulk Product a6f5cc74 | Sports & Outdoors | $405.91 | 369 | ★ 1.9 | 39 | BULK-01235b75 |
| 18939 | Bulk Product 1363eabe | Books | $686.81 | 119 | ★ 0.5 | 82 | BULK-e9871d6e |
| 18940 | Bulk Product 2e2d0924 | Clothing | $898.60 | 90 | ★ 3.8 | 47 | BULK-5d8391c4 |
| 18941 | Bulk Product 44fb4272 | Books | $673.90 | 412 | ★ 3.4 | 35 | BULK-107c5388 |
| 18942 | Bulk Product 2cb89f33 | Electronics | $157.80 | 179 | ★ 2.7 | 68 | BULK-27414efc |
| 18943 | Bulk Product 37620d33 | Books | $225.88 | 199 | ★ 3.1 | 8 | BULK-acb98250 |
| 18944 | Bulk Product 65340c2b | Toys & Games | $103.57 | 204 | ★ 3.5 | 90 | BULK-f6613f98 |
| 18945 | Bulk Product f4c0c338 | Home & Garden | $538.53 | 172 | ★ 4.1 | 76 | BULK-2d5eba1d |
| 18946 | Bulk Product 8834e9e2 | Sports & Outdoors | $520.98 | 8 | ★ 0.0 | 26 | BULK-8b58189b |
| 18947 | Bulk Product 28ed44ca | Clothing | $710.39 | 396 | ★ 0.1 | 17 | BULK-7c6798a3 |
| 18948 | Bulk Product d1e94bad | Toys & Games | $507.87 | 198 | ★ 4.9 | 29 | BULK-adf300be |
| 18949 | Bulk Product c55b5342 | Home & Garden | $374.53 | 252 | ★ 2.5 | 96 | BULK-96cd3b86 |
| 18950 | Bulk Product 64795ff7 | Sports & Outdoors | $294.21 | 408 | ★ 4.6 | 42 | BULK-8dc522e3 |
| 18951 | Bulk Product 20b458dc | Sports & Outdoors | $460.13 | 82 | ★ 1.7 | 62 | BULK-0aabc91e |
| 18952 | Bulk Product b15820be | Home & Garden | $19.45 | 376 | ★ 0.8 | 47 | BULK-d7a3169a |
| 18953 | Bulk Product a88b5872 | Clothing | $388.88 | 421 | ★ 2.7 | 54 | BULK-91f6fe26 |
| 18954 | Bulk Product 1dd23560 | Toys & Games | $793.17 | 472 | ★ 1.7 | 97 | BULK-5fd8781c |
| 18955 | Bulk Product 74a53e19 | Electronics | $339.75 | 366 | ★ 5.0 | 1 | BULK-ec1414f9 |
| 18956 | Bulk Product 32ac4224 | Books | $919.30 | 108 | ★ 3.3 | 20 | BULK-640120d7 |
| 18957 | Bulk Product c608160f | Electronics | $443.57 | 66 | ★ 0.0 | 71 | BULK-27bbd103 |
| 18958 | Bulk Product 398d02b2 | Electronics | $853.06 | 174 | ★ 2.6 | 43 | BULK-9afc56fd |
| 18959 | Bulk Product 2ffdc8d6 | Toys & Games | $77.44 | 232 | ★ 5.0 | 41 | BULK-1143c432 |
// 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
};
}