Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 11710 | Bulk Product b8b80f92 | Electronics | $949.14 | 169 | ★ 0.0 | 7 | BULK-b239a002 |
| 11711 | Bulk Product 821cd18c | Toys & Games | $273.11 | 224 | ★ 3.1 | 21 | BULK-92487d4d |
| 11712 | Bulk Product 9c422c7a | Toys & Games | $842.04 | 454 | ★ 3.2 | 11 | BULK-c1f5743e |
| 11713 | Bulk Product 2d45e1b5 | Electronics | $950.79 | 209 | ★ 4.4 | 16 | BULK-d31c1000 |
| 11714 | Bulk Product b63856b9 | Electronics | $182.75 | 220 | ★ 3.7 | 32 | BULK-5debafb9 |
| 11715 | Bulk Product 78d16a49 | Electronics | $53.52 | 322 | ★ 3.0 | 64 | BULK-0f665867 |
| 11716 | Bulk Product 50e1b140 | Sports & Outdoors | $990.13 | 448 | ★ 4.7 | 77 | BULK-fd5c306a |
| 11717 | Bulk Product 1d322fb2 | Toys & Games | $176.00 | 274 | ★ 1.9 | 22 | BULK-fa9ca2d7 |
| 11718 | Bulk Product 051645f4 | Toys & Games | $623.03 | 321 | ★ 4.0 | 29 | BULK-80ffc1d3 |
| 11719 | Bulk Product ba48e099 | Toys & Games | $143.32 | 389 | ★ 0.4 | 7 | BULK-f0adb345 |
| 11720 | Bulk Product 9af08207 | Books | $578.87 | 399 | ★ 2.7 | 42 | BULK-292bf19a |
| 11721 | Bulk Product f7e1e227 | Sports & Outdoors | $188.89 | 143 | ★ 4.7 | 79 | BULK-cb38f4d9 |
| 11722 | Bulk Product 0a875a1e | Books | $856.84 | 179 | ★ 1.3 | 55 | BULK-5cb6239e |
| 11723 | Bulk Product fb13146b | Toys & Games | $574.44 | 51 | ★ 3.2 | 85 | BULK-e856ee07 |
| 11724 | Bulk Product d053beee | Home & Garden | $274.62 | 35 | ★ 3.2 | 70 | BULK-19fdfcf0 |
| 11725 | Bulk Product c260644a | Electronics | $682.23 | 256 | ★ 3.5 | 85 | BULK-65bb4b08 |
| 11726 | Bulk Product 9e559e93 | Clothing | $349.93 | 12 | ★ 2.2 | 40 | BULK-673ab6f1 |
| 11727 | Bulk Product 3bee12da | Toys & Games | $220.30 | 51 | ★ 1.2 | 61 | BULK-69b056aa |
| 11728 | Bulk Product 74ca906e | Clothing | $743.41 | 476 | ★ 4.8 | 80 | BULK-63ce4d44 |
| 11729 | Bulk Product 198ca39b | Clothing | $855.78 | 420 | ★ 1.1 | 68 | BULK-06a1b965 |
| 11730 | Bulk Product 555d9e50 | Books | $1,000.31 | 42 | ★ 0.7 | 62 | BULK-bc0fc811 |
| 11731 | Bulk Product 85cd87c6 | Books | $397.19 | 337 | ★ 2.5 | 27 | BULK-98647a8b |
| 11732 | Bulk Product 16f90526 | Clothing | $364.77 | 203 | ★ 0.5 | 65 | BULK-d1d4ccf9 |
| 11733 | Bulk Product 2a902957 | Sports & Outdoors | $644.12 | 433 | ★ 5.0 | 77 | BULK-880825b0 |
| 11734 | Bulk Product a5905f55 | Electronics | $418.38 | 219 | ★ 2.1 | 2 | BULK-a822149d |
// 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
};
}