Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 5085 | Bulk Product 1b1b9fbc | Toys & Games | $370.57 | 292 | ★ 2.3 | 16 | BULK-d9079113 |
| 5086 | Bulk Product 388af76b | Clothing | $577.77 | 99 | ★ 0.3 | 43 | BULK-5f3494ad |
| 5087 | Bulk Product c8be8d2f | Toys & Games | $923.66 | 470 | ★ 4.1 | 40 | BULK-8632a0f4 |
| 5088 | Bulk Product 677647bf | Books | $790.42 | 437 | ★ 2.1 | 74 | BULK-21db85b4 |
| 5089 | Bulk Product abe82ddb | Electronics | $826.09 | 1 | ★ 4.3 | 94 | BULK-856a1582 |
| 5090 | Bulk Product 6d0e61d8 | Toys & Games | $779.79 | 39 | ★ 2.4 | 9 | BULK-d1c67cd1 |
| 5091 | Bulk Product 7689348b | Home & Garden | $850.47 | 355 | ★ 2.6 | 31 | BULK-8b48a25d |
| 5092 | Bulk Product 4f67de8a | Books | $42.01 | 194 | ★ 3.9 | 24 | BULK-2791b421 |
| 5093 | Bulk Product ecd2d52a | Books | $447.22 | 250 | ★ 2.2 | 0 | BULK-5c867d37 |
| 5094 | Bulk Product a6270d7b | Books | $421.16 | 83 | ★ 0.1 | 97 | BULK-e36bda46 |
| 5095 | Bulk Product eba66682 | Home & Garden | $89.77 | 308 | ★ 0.0 | 20 | BULK-3fcd7bae |
| 5096 | Bulk Product 348867f4 | Books | $213.44 | 165 | ★ 4.0 | 97 | BULK-7db851bb |
| 5097 | Bulk Product 83248349 | Electronics | $337.16 | 251 | ★ 3.6 | 48 | BULK-efe01ce9 |
| 5098 | Bulk Product 7abbeb89 | Toys & Games | $562.56 | 459 | ★ 2.0 | 44 | BULK-db2f297c |
| 5099 | Bulk Product eeaee5a5 | Books | $420.48 | 471 | ★ 4.9 | 98 | BULK-fac2c21a |
| 5100 | Bulk Product 7f2dd930 | Toys & Games | $40.27 | 297 | ★ 2.3 | 31 | BULK-5b0ff847 |
| 5101 | Bulk Product 46d3376d | Toys & Games | $529.31 | 314 | ★ 3.6 | 5 | BULK-016e9127 |
| 5102 | Bulk Product 1bd4d697 | Home & Garden | $321.40 | 389 | ★ 3.2 | 27 | BULK-aeaaf66b |
| 5103 | Bulk Product cada88ed | Clothing | $512.81 | 267 | ★ 2.2 | 1 | BULK-220d339c |
| 5104 | Bulk Product 379ec181 | Clothing | $214.09 | 258 | ★ 4.4 | 61 | BULK-f29c8ad2 |
| 5105 | Bulk Product 9e8dbda1 | Toys & Games | $229.85 | 162 | ★ 1.6 | 95 | BULK-023489d8 |
| 5106 | Bulk Product 2a9cc591 | Toys & Games | $982.66 | 171 | ★ 2.3 | 9 | BULK-06154e8f |
| 5107 | Bulk Product e1885da7 | Sports & Outdoors | $879.68 | 203 | ★ 2.4 | 55 | BULK-b61afb9f |
| 5108 | Bulk Product 8cbe618c | Home & Garden | $652.28 | 103 | ★ 2.9 | 89 | BULK-2202d3b2 |
| 5109 | Bulk Product a6cdc97f | Toys & Games | $878.69 | 376 | ★ 0.7 | 20 | BULK-28fba2e1 |
// 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
};
}