Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 15010 | Bulk Product f6dbf412 | Sports & Outdoors | $81.72 | 387 | ★ 1.7 | 35 | BULK-043939c0 |
| 15011 | Bulk Product 61450cdd | Books | $730.77 | 466 | ★ 2.0 | 67 | BULK-aa896f49 |
| 15012 | Bulk Product 0d1a37dc | Sports & Outdoors | $483.93 | 415 | ★ 0.8 | 81 | BULK-cc8710b2 |
| 15013 | Bulk Product 4ef76c4e | Toys & Games | $797.47 | 320 | ★ 1.6 | 6 | BULK-065aa678 |
| 15014 | Bulk Product 454bdf29 | Electronics | $581.60 | 304 | ★ 0.6 | 57 | BULK-07b5fcb1 |
| 15015 | Bulk Product 270f792a | Toys & Games | $794.14 | 95 | ★ 3.5 | 49 | BULK-06893fe8 |
| 15016 | Bulk Product bb8b818e | Electronics | $393.08 | 205 | ★ 4.6 | 8 | BULK-d40b8e15 |
| 15017 | Bulk Product 73bac3b2 | Books | $444.61 | 50 | ★ 2.9 | 53 | BULK-44f59b8b |
| 15018 | Bulk Product 69d15a1c | Sports & Outdoors | $232.41 | 236 | ★ 0.6 | 37 | BULK-f01c83cc |
| 15019 | Bulk Product 0f693d3f | Books | $861.35 | 26 | ★ 4.6 | 51 | BULK-09226739 |
| 15020 | Bulk Product fa890357 | Sports & Outdoors | $16.18 | 90 | ★ 2.1 | 76 | BULK-ffb16bb1 |
| 15021 | Bulk Product 33661580 | Books | $335.27 | 409 | ★ 2.5 | 90 | BULK-d619116b |
| 15022 | Bulk Product fa1d16f4 | Home & Garden | $754.20 | 400 | ★ 1.6 | 58 | BULK-9101d38d |
| 15023 | Bulk Product 7b46c26d | Toys & Games | $335.63 | 145 | ★ 0.5 | 16 | BULK-70ed4965 |
| 15024 | Bulk Product 1fbee69d | Home & Garden | $784.98 | 295 | ★ 0.6 | 37 | BULK-fef768db |
| 15025 | Bulk Product c23f26fc | Clothing | $666.13 | 147 | ★ 3.7 | 86 | BULK-9031f8a2 |
| 15026 | Bulk Product 1e7ff375 | Electronics | $910.88 | 42 | ★ 3.0 | 23 | BULK-d7416007 |
| 15027 | Bulk Product b65a9ac7 | Toys & Games | $82.11 | 206 | ★ 1.1 | 72 | BULK-d7e7713f |
| 15028 | Bulk Product 8290b457 | Toys & Games | $342.00 | 27 | ★ 4.9 | 44 | BULK-7ea9010f |
| 15029 | Bulk Product d25760ae | Electronics | $465.36 | 473 | ★ 1.8 | 33 | BULK-43c51d3a |
| 15030 | Bulk Product 1903b970 | Home & Garden | $156.56 | 475 | ★ 4.8 | 10 | BULK-c93f45e9 |
| 15031 | Bulk Product bdd116fe | Books | $166.83 | 344 | ★ 1.1 | 69 | BULK-d0066dc6 |
| 15032 | Bulk Product 051c2767 | Home & Garden | $716.31 | 482 | ★ 1.8 | 21 | BULK-9015125d |
| 15033 | Bulk Product a84838f5 | Books | $130.98 | 431 | ★ 2.2 | 91 | BULK-6a5d7094 |
| 15034 | Bulk Product 84142ad9 | Clothing | $902.06 | 490 | ★ 1.7 | 91 | BULK-11c75ebd |
| 15035 | Bulk Product e6773c4c | Books | $742.96 | 278 | ★ 3.8 | 89 | BULK-b19c96c5 |
| 15036 | Bulk Product 74b36018 | Toys & Games | $363.51 | 327 | ★ 1.8 | 85 | BULK-1307cc8b |
| 15037 | Bulk Product 9bcb3911 | Sports & Outdoors | $774.51 | 439 | ★ 4.3 | 77 | BULK-391bb6a7 |
| 15038 | Bulk Product 17ee8e0d | Home & Garden | $632.23 | 7 | ★ 0.7 | 62 | BULK-ebebf683 |
| 15039 | Bulk Product 0b507b7b | Books | $928.36 | 125 | ★ 1.2 | 69 | BULK-d64c1e0f |
| 15040 | Bulk Product 46d96d5e | Home & Garden | $658.33 | 240 | ★ 2.8 | 51 | BULK-2e441660 |
| 15041 | Bulk Product 4b73e4b2 | Books | $702.64 | 125 | ★ 1.9 | 36 | BULK-7a163ba8 |
| 15042 | Bulk Product 755ff577 | Clothing | $301.60 | 319 | ★ 2.4 | 6 | BULK-b11b6e1f |
| 15043 | Bulk Product 06ffafc2 | Electronics | $30.37 | 426 | ★ 1.9 | 87 | BULK-6b25a253 |
| 15044 | Bulk Product 92789018 | Sports & Outdoors | $997.75 | 52 | ★ 3.4 | 61 | BULK-073d3a9f |
| 15045 | Bulk Product 456e68ba | Toys & Games | $528.34 | 336 | ★ 3.6 | 38 | BULK-8fef2158 |
| 15046 | Bulk Product bbc41eb0 | Electronics | $724.11 | 204 | ★ 0.2 | 44 | BULK-896bae5d |
| 15047 | Bulk Product 5757ca10 | Home & Garden | $427.04 | 203 | ★ 3.9 | 11 | BULK-83e08f8c |
| 15048 | Bulk Product 06af3271 | Books | $949.67 | 57 | ★ 0.3 | 48 | BULK-be110cd9 |
| 15049 | Bulk Product f7d481d2 | Clothing | $632.51 | 432 | ★ 4.1 | 76 | BULK-ee9751ef |
| 15050 | Bulk Product 6b3e9513 | Books | $127.54 | 462 | ★ 4.2 | 55 | BULK-0db3084b |
| 15051 | Bulk Product ea4b4812 | Sports & Outdoors | $333.94 | 491 | ★ 1.0 | 55 | BULK-d7163fca |
| 15052 | Bulk Product ed7edf13 | Home & Garden | $303.93 | 11 | ★ 4.5 | 17 | BULK-50a4f7aa |
| 15053 | Bulk Product ad151d5e | Electronics | $322.30 | 295 | ★ 3.8 | 48 | BULK-81113405 |
| 15054 | Bulk Product a5ffa130 | Clothing | $654.51 | 136 | ★ 4.9 | 37 | BULK-254b1426 |
| 15055 | Bulk Product 1a117d87 | Toys & Games | $233.30 | 302 | ★ 2.6 | 53 | BULK-ba550767 |
| 15056 | Bulk Product 969005a1 | Electronics | $174.83 | 339 | ★ 2.7 | 31 | BULK-0942fcf8 |
| 15057 | Bulk Product 94e4513a | Home & Garden | $289.94 | 231 | ★ 3.6 | 6 | BULK-2730e009 |
| 15058 | Bulk Product e1509528 | Clothing | $391.69 | 378 | ★ 4.0 | 90 | BULK-a2a1ac66 |
| 15059 | Bulk Product d0ea732e | Sports & Outdoors | $377.79 | 137 | ★ 3.5 | 82 | BULK-e0fc9178 |
// 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
};
}