Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 9960 | Bulk Product be0aae2f | Toys & Games | $627.29 | 411 | ★ 3.4 | 54 | BULK-09a2eb82 |
| 9961 | Bulk Product 8bca77bd | Electronics | $474.96 | 48 | ★ 4.5 | 22 | BULK-ae5ae77f |
| 9962 | Bulk Product 525a1b16 | Clothing | $602.99 | 138 | ★ 4.0 | 69 | BULK-1149c84b |
| 9963 | Bulk Product 4e2c0a7f | Home & Garden | $610.78 | 468 | ★ 0.4 | 52 | BULK-e383b74f |
| 9964 | Bulk Product c8f93528 | Sports & Outdoors | $699.10 | 304 | ★ 0.1 | 65 | BULK-91e78ace |
| 9965 | Bulk Product 9558669e | Electronics | $63.85 | 478 | ★ 1.1 | 56 | BULK-84b3d669 |
| 9966 | Bulk Product f43d150c | Sports & Outdoors | $45.69 | 485 | ★ 0.3 | 7 | BULK-4cc44020 |
| 9967 | Bulk Product ce185969 | Home & Garden | $868.75 | 150 | ★ 2.5 | 73 | BULK-8a4d1668 |
| 9968 | Bulk Product b1250be8 | Home & Garden | $963.59 | 189 | ★ 3.8 | 94 | BULK-2d6886a1 |
| 9969 | Bulk Product c99816b1 | Electronics | $681.37 | 178 | ★ 3.3 | 15 | BULK-e355d86a |
| 9970 | Bulk Product 2b9aa4d7 | Books | $249.50 | 399 | ★ 4.8 | 46 | BULK-2487b0e3 |
| 9971 | Bulk Product 6e5b5fae | Sports & Outdoors | $320.58 | 445 | ★ 4.8 | 78 | BULK-0fb6310d |
| 9972 | Bulk Product d4d21444 | Toys & Games | $311.26 | 31 | ★ 1.4 | 18 | BULK-9153d6fa |
| 9973 | Bulk Product bb6c45fd | Toys & Games | $417.25 | 90 | ★ 2.2 | 44 | BULK-942c22aa |
| 9974 | Bulk Product 1eea8999 | Electronics | $234.64 | 177 | ★ 1.5 | 9 | BULK-c133b005 |
| 9975 | Bulk Product 77edc7ec | Electronics | $50.92 | 262 | ★ 3.9 | 52 | BULK-9d2559ff |
| 9976 | Bulk Product e2512b00 | Toys & Games | $122.00 | 177 | ★ 2.5 | 54 | BULK-7b1d1d9d |
| 9977 | Bulk Product 225b566b | Books | $197.78 | 347 | ★ 2.5 | 24 | BULK-8043c7f4 |
| 9978 | Bulk Product e5002e63 | Electronics | $207.29 | 125 | ★ 3.2 | 13 | BULK-fc5321fa |
| 9979 | Bulk Product d2559771 | Clothing | $254.53 | 97 | ★ 2.6 | 48 | BULK-7fcf6142 |
| 9980 | Bulk Product 6a6981be | Clothing | $862.44 | 457 | ★ 1.3 | 37 | BULK-672c0ec9 |
| 9981 | Bulk Product ac4e4d61 | Home & Garden | $314.38 | 460 | ★ 2.2 | 73 | BULK-ce4269b0 |
| 9982 | Bulk Product 2a94ae1f | Sports & Outdoors | $949.58 | 417 | ★ 3.9 | 62 | BULK-e707e8ce |
| 9983 | Bulk Product e97d7361 | Clothing | $247.25 | 235 | ★ 0.9 | 62 | BULK-c3278791 |
| 9984 | Bulk Product d21ea123 | Clothing | $659.82 | 41 | ★ 2.1 | 85 | BULK-e268e116 |
// 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
};
}