Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 8860 | Bulk Product aefa819f | Electronics | $501.70 | 176 | ★ 1.2 | 61 | BULK-cdaf9df4 |
| 8861 | Bulk Product 55cd8b2e | Toys & Games | $607.98 | 336 | ★ 3.0 | 68 | BULK-8c8d4b79 |
| 8862 | Bulk Product c172fc22 | Toys & Games | $669.21 | 266 | ★ 0.3 | 57 | BULK-eb2f739e |
| 8863 | Bulk Product f33bd357 | Home & Garden | $65.63 | 343 | ★ 0.4 | 73 | BULK-214f570a |
| 8864 | Bulk Product c08f80cc | Books | $318.68 | 180 | ★ 2.5 | 75 | BULK-87f60952 |
| 8865 | Bulk Product 63d8c038 | Toys & Games | $38.02 | 56 | ★ 0.0 | 29 | BULK-7759c37b |
| 8866 | Bulk Product 1812fc82 | Toys & Games | $592.87 | 41 | ★ 1.6 | 99 | BULK-bbd24fb3 |
| 8867 | Bulk Product 38893fcb | Home & Garden | $709.63 | 280 | ★ 2.4 | 10 | BULK-b600bd74 |
| 8868 | Bulk Product 0fb8a957 | Books | $227.44 | 483 | ★ 3.0 | 12 | BULK-60eb76dd |
| 8869 | Bulk Product f2323bb4 | Electronics | $884.89 | 87 | ★ 4.1 | 20 | BULK-6202bc0f |
| 8870 | Bulk Product 70570e55 | Home & Garden | $345.39 | 324 | ★ 3.3 | 62 | BULK-f6edf518 |
| 8871 | Bulk Product 14748a8d | Clothing | $265.84 | 494 | ★ 3.6 | 33 | BULK-edf30ea6 |
| 8872 | Bulk Product 8bb9b5ec | Home & Garden | $361.35 | 33 | ★ 3.1 | 9 | BULK-6738019a |
| 8873 | Bulk Product 7cc3343a | Electronics | $945.11 | 486 | ★ 3.5 | 40 | BULK-4a04613b |
| 8874 | Bulk Product a4fe3ea2 | Electronics | $260.63 | 401 | ★ 4.6 | 69 | BULK-22883028 |
| 8875 | Bulk Product 8a82a3db | Books | $207.88 | 284 | ★ 3.3 | 88 | BULK-fa4f57ff |
| 8876 | Bulk Product 30030bdd | Home & Garden | $375.33 | 147 | ★ 5.0 | 73 | BULK-6f36ed9d |
| 8877 | Bulk Product b7ea7c81 | Books | $950.19 | 293 | ★ 0.4 | 41 | BULK-56e69116 |
| 8878 | Bulk Product 6d9e5d8a | Toys & Games | $543.00 | 438 | ★ 1.9 | 39 | BULK-11e09ffb |
| 8879 | Bulk Product 9c7bce78 | Toys & Games | $269.39 | 2 | ★ 0.3 | 30 | BULK-937f24b3 |
| 8880 | Bulk Product bb3262c0 | Clothing | $895.73 | 107 | ★ 2.4 | 37 | BULK-e7476d38 |
| 8881 | Bulk Product dea3d2de | Sports & Outdoors | $762.59 | 442 | ★ 1.1 | 11 | BULK-e326de8c |
| 8882 | Bulk Product 45bf9749 | Electronics | $64.51 | 323 | ★ 4.8 | 84 | BULK-38a760bd |
| 8883 | Bulk Product 69257e70 | Books | $645.26 | 350 | ★ 0.5 | 21 | BULK-11b3c318 |
| 8884 | Bulk Product 8d257a95 | Sports & Outdoors | $954.82 | 339 | ★ 1.1 | 81 | BULK-151a2ea8 |
// 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
};
}