Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 9385 | Bulk Product d8726f41 | Books | $166.90 | 366 | ★ 1.1 | 90 | BULK-3cd30c14 |
| 9386 | Bulk Product 5f76fe42 | Clothing | $450.63 | 132 | ★ 0.4 | 15 | BULK-918dd969 |
| 9387 | Bulk Product 0f09eb0e | Books | $480.83 | 471 | ★ 1.7 | 66 | BULK-625e3763 |
| 9388 | Bulk Product fb2841c2 | Electronics | $428.76 | 130 | ★ 3.2 | 71 | BULK-8a001ecc |
| 9389 | Bulk Product 8e7d8950 | Books | $592.82 | 201 | ★ 2.8 | 14 | BULK-a19034eb |
| 9390 | Bulk Product 1ba18695 | Clothing | $422.42 | 115 | ★ 2.1 | 97 | BULK-1a42af09 |
| 9391 | Bulk Product 3146f98b | Sports & Outdoors | $266.52 | 17 | ★ 1.6 | 94 | BULK-5c17cc5d |
| 9392 | Bulk Product 3800c748 | Books | $214.96 | 415 | ★ 0.9 | 31 | BULK-b6b27797 |
| 9393 | Bulk Product ae79f8f1 | Toys & Games | $732.66 | 53 | ★ 2.1 | 94 | BULK-65cb1a7e |
| 9394 | Bulk Product 387c02cc | Toys & Games | $189.43 | 94 | ★ 1.2 | 61 | BULK-898cb932 |
| 9395 | Bulk Product a71b9037 | Electronics | $34.43 | 30 | ★ 4.6 | 41 | BULK-4aea7c33 |
| 9396 | Bulk Product baf5a3a0 | Books | $503.66 | 339 | ★ 2.5 | 2 | BULK-1e05266a |
| 9397 | Bulk Product 1b519566 | Sports & Outdoors | $202.32 | 207 | ★ 0.9 | 56 | BULK-48d23efe |
| 9398 | Bulk Product ae639d5c | Sports & Outdoors | $36.06 | 69 | ★ 4.7 | 67 | BULK-b528bb14 |
| 9399 | Bulk Product 2fe6f736 | Toys & Games | $698.10 | 79 | ★ 1.8 | 91 | BULK-1ed06f83 |
| 9400 | Bulk Product f106b66c | Home & Garden | $664.06 | 247 | ★ 1.5 | 73 | BULK-0edf250c |
| 9401 | Bulk Product 3f1b9eeb | Home & Garden | $629.12 | 18 | ★ 2.0 | 68 | BULK-3407bba3 |
| 9402 | Bulk Product cb32ca1e | Home & Garden | $562.14 | 393 | ★ 1.1 | 47 | BULK-092c191b |
| 9403 | Bulk Product fd1d01f7 | Books | $413.63 | 422 | ★ 0.1 | 61 | BULK-5b460caa |
| 9404 | Bulk Product 7fa1709c | Toys & Games | $681.20 | 112 | ★ 3.4 | 10 | BULK-b2594d96 |
| 9405 | Bulk Product 4b61c3d7 | Sports & Outdoors | $580.39 | 201 | ★ 0.6 | 97 | BULK-fdeff10e |
| 9406 | Bulk Product a8b76d7f | Clothing | $777.41 | 413 | ★ 3.1 | 45 | BULK-026bee18 |
| 9407 | Bulk Product ef6c85de | Books | $792.00 | 434 | ★ 1.9 | 30 | BULK-223573e3 |
| 9408 | Bulk Product 16a46e59 | Toys & Games | $408.76 | 449 | ★ 2.1 | 0 | BULK-0315bff6 |
| 9409 | Bulk Product f86f980d | Clothing | $653.85 | 85 | ★ 3.6 | 97 | BULK-3a5d8892 |
// 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
};
}