Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 21560 | Bulk Product 036e78ee | Clothing | $895.55 | 209 | ★ 3.6 | 39 | BULK-9e817e08 |
| 21561 | Bulk Product 07ec6e50 | Clothing | $583.12 | 167 | ★ 1.9 | 29 | BULK-dd481d03 |
| 21562 | Bulk Product b6a45918 | Sports & Outdoors | $312.80 | 303 | ★ 3.3 | 96 | BULK-8c4937a3 |
| 21563 | Bulk Product c50f47c4 | Electronics | $914.64 | 332 | ★ 5.0 | 55 | BULK-9b581c7f |
| 21564 | Bulk Product ccff8dca | Home & Garden | $604.31 | 227 | ★ 2.9 | 32 | BULK-d7ee7663 |
| 21565 | Bulk Product 30a50517 | Clothing | $280.12 | 37 | ★ 3.3 | 15 | BULK-64b10d80 |
| 21566 | Bulk Product 09367dda | Home & Garden | $815.92 | 480 | ★ 2.4 | 18 | BULK-2eb0088a |
| 21567 | Bulk Product 7aed117a | Toys & Games | $550.53 | 359 | ★ 3.8 | 4 | BULK-462d5428 |
| 21568 | Bulk Product d80cbeb0 | Clothing | $290.46 | 263 | ★ 1.4 | 16 | BULK-b6ecd3b9 |
| 21569 | Bulk Product 77ae67cf | Clothing | $819.35 | 228 | ★ 1.0 | 89 | BULK-83d8d56e |
| 21570 | Bulk Product 5b0b5dea | Home & Garden | $796.20 | 77 | ★ 0.7 | 89 | BULK-e1e4ea9b |
| 21571 | Bulk Product dc63d80f | Electronics | $13.98 | 403 | ★ 3.7 | 32 | BULK-b25b5150 |
| 21572 | Bulk Product 5f3f5261 | Sports & Outdoors | $946.24 | 409 | ★ 0.4 | 66 | BULK-ce308a16 |
| 21573 | Bulk Product d784779f | Sports & Outdoors | $792.37 | 235 | ★ 2.2 | 25 | BULK-50d5de7e |
| 21574 | Bulk Product c2de3be9 | Clothing | $46.56 | 371 | ★ 2.6 | 89 | BULK-98cacf10 |
| 21575 | Bulk Product 752660ce | Sports & Outdoors | $157.98 | 418 | ★ 1.4 | 95 | BULK-e847dfb8 |
| 21576 | Bulk Product 8b94731c | Toys & Games | $62.26 | 201 | ★ 4.1 | 27 | BULK-f344b776 |
| 21577 | Bulk Product 7507e28a | Home & Garden | $268.81 | 129 | ★ 1.2 | 77 | BULK-32702c72 |
| 21578 | Bulk Product 5c754dd0 | Clothing | $921.51 | 49 | ★ 3.9 | 96 | BULK-13ad0e19 |
| 21579 | Bulk Product 4cb252d6 | Sports & Outdoors | $246.59 | 22 | ★ 2.1 | 12 | BULK-984dadc3 |
| 21580 | Bulk Product f9ebd759 | Home & Garden | $929.61 | 443 | ★ 1.3 | 69 | BULK-be028ad2 |
| 21581 | Bulk Product 5ef78954 | Home & Garden | $750.97 | 332 | ★ 0.1 | 77 | BULK-6d659ebd |
| 21582 | Bulk Product cb5bf2b6 | Toys & Games | $409.75 | 336 | ★ 0.5 | 59 | BULK-a2739931 |
| 21583 | Bulk Product a2ab6f4a | Home & Garden | $585.67 | 252 | ★ 4.4 | 46 | BULK-361955dd |
| 21584 | Bulk Product 4200089d | Sports & Outdoors | $723.93 | 51 | ★ 2.9 | 27 | BULK-88b4f0ad |
// 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
};
}