Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 12035 | Bulk Product 0f279729 | Electronics | $88.39 | 202 | ★ 2.9 | 45 | BULK-d5324c6d |
| 12036 | Bulk Product 1146c662 | Sports & Outdoors | $230.08 | 342 | ★ 2.7 | 58 | BULK-e7ee818f |
| 12037 | Bulk Product 67c796a6 | Electronics | $18.12 | 145 | ★ 3.8 | 11 | BULK-5a4db793 |
| 12038 | Bulk Product ba38e1ad | Sports & Outdoors | $359.39 | 202 | ★ 0.9 | 41 | BULK-f99b666d |
| 12039 | Bulk Product 54eee4d4 | Sports & Outdoors | $253.83 | 165 | ★ 3.0 | 96 | BULK-04732806 |
| 12040 | Bulk Product 9f3df142 | Sports & Outdoors | $105.07 | 94 | ★ 1.1 | 14 | BULK-5448da65 |
| 12041 | Bulk Product b051d687 | Toys & Games | $854.92 | 437 | ★ 4.5 | 36 | BULK-e69a4ae5 |
| 12042 | Bulk Product 559ddae3 | Books | $315.62 | 175 | ★ 0.3 | 44 | BULK-65d865e4 |
| 12043 | Bulk Product bbf4853d | Home & Garden | $357.90 | 467 | ★ 0.7 | 92 | BULK-bc2ad907 |
| 12044 | Bulk Product 3ffa665f | Books | $770.54 | 307 | ★ 4.4 | 72 | BULK-ec7cc0ee |
| 12045 | Bulk Product 8bba479f | Sports & Outdoors | $670.26 | 376 | ★ 1.6 | 20 | BULK-d1ccb85a |
| 12046 | Bulk Product cbf4bd21 | Clothing | $978.06 | 391 | ★ 3.7 | 44 | BULK-3dd1e4d0 |
| 12047 | Bulk Product afeb7025 | Clothing | $621.34 | 103 | ★ 2.1 | 25 | BULK-af622945 |
| 12048 | Bulk Product f7290973 | Books | $972.52 | 195 | ★ 1.5 | 38 | BULK-50e986fb |
| 12049 | Bulk Product 6cb0db92 | Home & Garden | $54.95 | 91 | ★ 4.6 | 9 | BULK-8f857cd9 |
| 12050 | Bulk Product 30bb8dfe | Toys & Games | $14.11 | 43 | ★ 1.9 | 24 | BULK-294ceb44 |
| 12051 | Bulk Product 3553915a | Toys & Games | $323.76 | 181 | ★ 1.2 | 21 | BULK-54b68b54 |
| 12052 | Bulk Product 6edb6055 | Electronics | $704.26 | 131 | ★ 3.2 | 99 | BULK-65bcb224 |
| 12053 | Bulk Product a32ae2d2 | Toys & Games | $448.41 | 360 | ★ 4.6 | 36 | BULK-caeae80c |
| 12054 | Bulk Product f726ea28 | Toys & Games | $889.31 | 194 | ★ 0.4 | 86 | BULK-818b99af |
| 12055 | Bulk Product 6dedf1da | Sports & Outdoors | $968.96 | 163 | ★ 3.7 | 79 | BULK-31bb2389 |
| 12056 | Bulk Product b954033a | Books | $30.68 | 326 | ★ 2.7 | 30 | BULK-ac90f5b4 |
| 12057 | Bulk Product 05245e92 | Clothing | $289.84 | 186 | ★ 4.4 | 50 | BULK-97fd9389 |
| 12058 | Bulk Product f37335cf | Electronics | $561.42 | 471 | ★ 2.7 | 59 | BULK-b6a1c303 |
| 12059 | Bulk Product 5baf15a9 | Clothing | $42.91 | 385 | ★ 1.8 | 32 | BULK-5c769de2 |
// 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
};
}