Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 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
};
}