Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 5435 | Bulk Product 850f4cff | Electronics | $882.41 | 157 | ★ 3.7 | 26 | BULK-daee7cc7 |
| 5436 | Bulk Product cfb0cc0a | Books | $642.94 | 310 | ★ 3.8 | 89 | BULK-c567fc3c |
| 5437 | Bulk Product fdad24e1 | Clothing | $484.32 | 415 | ★ 1.9 | 22 | BULK-ee6145c2 |
| 5438 | Bulk Product 2dc10da9 | Electronics | $525.17 | 85 | ★ 2.4 | 97 | BULK-f23d0fb8 |
| 5439 | Bulk Product 7a5b0b2e | Books | $899.33 | 149 | ★ 3.8 | 23 | BULK-b080d33a |
| 5440 | Bulk Product 90a87b01 | Clothing | $995.63 | 238 | ★ 1.6 | 20 | BULK-912325e5 |
| 5441 | Bulk Product 9a50ad13 | Home & Garden | $531.50 | 340 | ★ 1.7 | 71 | BULK-f1389c0b |
| 5442 | Bulk Product 74096de8 | Electronics | $315.81 | 72 | ★ 1.1 | 44 | BULK-b247b7ef |
| 5443 | Bulk Product c069a315 | Home & Garden | $228.50 | 18 | ★ 0.9 | 90 | BULK-85b49cab |
| 5444 | Bulk Product a318dfeb | Electronics | $131.45 | 342 | ★ 0.3 | 95 | BULK-00b48198 |
| 5445 | Bulk Product 1547f585 | Toys & Games | $520.35 | 318 | ★ 2.9 | 52 | BULK-0d294760 |
| 5446 | Bulk Product 37d81441 | Electronics | $144.27 | 334 | ★ 3.2 | 88 | BULK-1fe48e13 |
| 5447 | Bulk Product 756d881f | Books | $684.55 | 468 | ★ 3.5 | 4 | BULK-cfe069a9 |
| 5448 | Bulk Product 77086905 | Books | $39.65 | 165 | ★ 4.6 | 16 | BULK-5852ccb3 |
| 5449 | Bulk Product 11a12246 | Sports & Outdoors | $828.73 | 47 | ★ 0.8 | 0 | BULK-5baaa3f0 |
| 5450 | Bulk Product 2901d37f | Sports & Outdoors | $106.85 | 257 | ★ 0.7 | 79 | BULK-7f381910 |
| 5451 | Bulk Product 54a56cbb | Clothing | $386.60 | 250 | ★ 4.2 | 93 | BULK-f03d6e48 |
| 5452 | Bulk Product 9a944f52 | Toys & Games | $167.80 | 327 | ★ 3.5 | 25 | BULK-1af1ec02 |
| 5453 | Bulk Product 1cd59ab5 | Books | $183.33 | 175 | ★ 5.0 | 54 | BULK-da510fca |
| 5454 | Bulk Product 6b322046 | Books | $349.29 | 152 | ★ 3.4 | 15 | BULK-99b473d8 |
| 5455 | Bulk Product 2de6902c | Home & Garden | $839.81 | 366 | ★ 4.5 | 36 | BULK-20bc4ae7 |
| 5456 | Bulk Product e3c8e4c7 | Books | $72.73 | 175 | ★ 4.1 | 68 | BULK-6e84c72b |
| 5457 | Bulk Product 0d0de6fc | Clothing | $382.37 | 187 | ★ 1.9 | 49 | BULK-c5dc4de2 |
| 5458 | Bulk Product a040046f | Electronics | $943.12 | 226 | ★ 1.5 | 26 | BULK-e295f1c0 |
| 5459 | Bulk Product e343ddf1 | Toys & Games | $273.26 | 334 | ★ 2.1 | 90 | BULK-7d2bdce8 |
// 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
};
}