Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 24210 | Bulk Product e3c3ce0a | Home & Garden | $329.50 | 458 | ★ 0.9 | 36 | BULK-c79c9cbf |
| 24211 | Bulk Product 819e72ed | Toys & Games | $312.94 | 216 | ★ 4.0 | 17 | BULK-df522470 |
| 24212 | Bulk Product 2ad6eb58 | Electronics | $469.64 | 237 | ★ 4.1 | 95 | BULK-c39688ad |
| 24213 | Bulk Product 3f2a3787 | Home & Garden | $505.28 | 427 | ★ 2.1 | 0 | BULK-4fa2f577 |
| 24214 | Bulk Product f0e31fc4 | Clothing | $620.44 | 139 | ★ 2.7 | 77 | BULK-d6e1e090 |
| 24215 | Bulk Product 5becce53 | Books | $676.60 | 68 | ★ 0.5 | 2 | BULK-dcd74fef |
| 24216 | Bulk Product 565d3622 | Toys & Games | $902.60 | 219 | ★ 2.8 | 44 | BULK-4eb0671b |
| 24217 | Bulk Product cec24dd4 | Electronics | $844.11 | 90 | ★ 4.0 | 27 | BULK-0b1a587b |
| 24218 | Bulk Product 0ccf6a3c | Clothing | $444.30 | 87 | ★ 4.4 | 1 | BULK-86f40566 |
| 24219 | Bulk Product 6675588f | Sports & Outdoors | $373.78 | 233 | ★ 3.8 | 59 | BULK-d652ed94 |
| 24220 | Bulk Product 70bca328 | Sports & Outdoors | $820.04 | 429 | ★ 4.4 | 82 | BULK-19cb1a26 |
| 24221 | Bulk Product 47a29a9e | Clothing | $275.53 | 95 | ★ 1.8 | 17 | BULK-169267e7 |
| 24222 | Bulk Product 94324a0f | Sports & Outdoors | $173.32 | 181 | ★ 0.1 | 27 | BULK-3e4f29f1 |
| 24223 | Bulk Product 09fd478c | Sports & Outdoors | $298.01 | 320 | ★ 0.7 | 28 | BULK-92b35193 |
| 24224 | Bulk Product 1a3d44fc | Electronics | $556.00 | 129 | ★ 4.2 | 88 | BULK-01e77511 |
| 24225 | Bulk Product 5f27a8c1 | Sports & Outdoors | $447.09 | 361 | ★ 0.6 | 76 | BULK-273cef03 |
| 24226 | Bulk Product a00fc693 | Electronics | $951.43 | 498 | ★ 1.3 | 98 | BULK-07bece2d |
| 24227 | Bulk Product 786fbaf8 | Clothing | $405.38 | 295 | ★ 4.8 | 39 | BULK-d3b538cb |
| 24228 | Bulk Product 13135d02 | Electronics | $883.83 | 162 | ★ 2.9 | 45 | BULK-3682eaf6 |
| 24229 | Bulk Product 83020007 | Clothing | $330.81 | 409 | ★ 2.1 | 11 | BULK-4f9939f7 |
| 24230 | Bulk Product 998be65e | Books | $922.88 | 21 | ★ 2.5 | 74 | BULK-c065e828 |
| 24231 | Bulk Product 4b7d756c | Electronics | $561.47 | 214 | ★ 1.1 | 41 | BULK-fb9bdecd |
| 24232 | Bulk Product 5eff88d5 | Sports & Outdoors | $218.11 | 10 | ★ 2.6 | 35 | BULK-8d00028d |
| 24233 | Bulk Product 73d1d22d | Home & Garden | $380.66 | 475 | ★ 4.0 | 55 | BULK-9bc232ed |
| 24234 | Bulk Product e248264c | Toys & Games | $941.26 | 62 | ★ 3.7 | 88 | BULK-f6ab70d2 |
| 24235 | Bulk Product 9f88bafe | Toys & Games | $998.54 | 348 | ★ 3.2 | 43 | BULK-86c85f50 |
| 24236 | Bulk Product d5b935f3 | Home & Garden | $810.28 | 94 | ★ 2.5 | 59 | BULK-b323678f |
| 24237 | Bulk Product 86d3173f | Books | $339.61 | 25 | ★ 0.7 | 54 | BULK-8b346968 |
| 24238 | Bulk Product 3f030904 | Electronics | $740.05 | 241 | ★ 2.6 | 84 | BULK-9d91cae7 |
| 24239 | Bulk Product 32b7a094 | Sports & Outdoors | $205.94 | 350 | ★ 3.7 | 57 | BULK-ac083fa6 |
| 24240 | Bulk Product ba4bd1e9 | Sports & Outdoors | $187.70 | 64 | ★ 3.4 | 0 | BULK-683ddd95 |
| 24241 | Bulk Product 9e0bae8c | Electronics | $850.86 | 191 | ★ 0.3 | 47 | BULK-2b962f55 |
| 24242 | Bulk Product 4af08285 | Clothing | $377.47 | 195 | ★ 1.0 | 20 | BULK-f5eb80e8 |
| 24243 | Bulk Product 49deb8ab | Electronics | $512.22 | 341 | ★ 3.6 | 30 | BULK-f9805643 |
| 24244 | Bulk Product f5b5d8fe | Books | $127.55 | 421 | ★ 0.2 | 21 | BULK-b3d596ea |
| 24245 | Bulk Product 88b9787d | Home & Garden | $571.47 | 225 | ★ 0.3 | 81 | BULK-48799089 |
| 24246 | Bulk Product d9767062 | Toys & Games | $902.87 | 344 | ★ 0.4 | 71 | BULK-5104db4a |
| 24247 | Bulk Product 57c4c6bf | Home & Garden | $564.15 | 30 | ★ 3.5 | 83 | BULK-691bd2f3 |
| 24248 | Bulk Product 1ea61eea | Books | $743.85 | 424 | ★ 2.5 | 86 | BULK-53075ba0 |
| 24249 | Bulk Product d3eba1da | Sports & Outdoors | $104.32 | 287 | ★ 0.8 | 16 | BULK-75d7e22a |
| 24250 | Bulk Product 2df1e459 | Electronics | $569.95 | 97 | ★ 1.6 | 84 | BULK-820938b4 |
| 24251 | Bulk Product 69bad8ff | Sports & Outdoors | $614.40 | 211 | ★ 1.5 | 99 | BULK-5ee338f9 |
| 24252 | Bulk Product f26e918c | Toys & Games | $259.60 | 102 | ★ 1.4 | 49 | BULK-96de34da |
| 24253 | Bulk Product 21796322 | Sports & Outdoors | $195.18 | 277 | ★ 3.7 | 3 | BULK-9f42e950 |
| 24254 | Bulk Product 8a192342 | Clothing | $187.94 | 318 | ★ 1.4 | 31 | BULK-22eca301 |
| 24255 | Bulk Product 14f3c605 | Home & Garden | $829.86 | 81 | ★ 3.3 | 55 | BULK-dc41e2b6 |
| 24256 | Bulk Product 8ba112ab | Home & Garden | $746.22 | 386 | ★ 0.2 | 88 | BULK-0fbacbef |
| 24257 | Bulk Product 06075b2c | Electronics | $444.30 | 157 | ★ 1.1 | 71 | BULK-91029418 |
| 24258 | Bulk Product f93370fa | Toys & Games | $690.72 | 58 | ★ 4.4 | 69 | BULK-f625557f |
| 24259 | Bulk Product fa79805a | Sports & Outdoors | $69.22 | 238 | ★ 0.4 | 72 | BULK-0fdb2f22 |
// 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
};
}