Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 17060 | Bulk Product 5beecd9f | Electronics | $99.12 | 193 | ★ 1.2 | 20 | BULK-09ea07ea |
| 17061 | Bulk Product 83d3f6b8 | Clothing | $44.57 | 31 | ★ 4.9 | 2 | BULK-577bf201 |
| 17062 | Bulk Product 4b9af20f | Clothing | $1,000.72 | 441 | ★ 2.5 | 51 | BULK-a31a5c72 |
| 17063 | Bulk Product ef1cc496 | Sports & Outdoors | $136.14 | 186 | ★ 0.0 | 32 | BULK-6561803a |
| 17064 | Bulk Product 03babc84 | Sports & Outdoors | $141.22 | 449 | ★ 1.4 | 99 | BULK-17fd7751 |
| 17065 | Bulk Product 405bad00 | Books | $436.84 | 30 | ★ 3.7 | 16 | BULK-4125c337 |
| 17066 | Bulk Product da190021 | Toys & Games | $622.49 | 423 | ★ 4.5 | 97 | BULK-bd80f346 |
| 17067 | Bulk Product 9303baa9 | Home & Garden | $44.63 | 196 | ★ 0.8 | 50 | BULK-cb3ea218 |
| 17068 | Bulk Product 7e26987c | Books | $288.42 | 206 | ★ 2.6 | 98 | BULK-9b30e0db |
| 17069 | Bulk Product 05f5c921 | Books | $111.74 | 496 | ★ 3.3 | 32 | BULK-8d73b8bc |
| 17070 | Bulk Product d5ebdff0 | Books | $34.88 | 252 | ★ 2.5 | 3 | BULK-66f00e3e |
| 17071 | Bulk Product 378c4edb | Toys & Games | $810.72 | 374 | ★ 5.0 | 73 | BULK-3cfee498 |
| 17072 | Bulk Product fb8bab42 | Books | $204.08 | 77 | ★ 1.5 | 24 | BULK-6d6b1984 |
| 17073 | Bulk Product 120716f5 | Sports & Outdoors | $678.79 | 254 | ★ 4.9 | 76 | BULK-12cc97b0 |
| 17074 | Bulk Product 9a80d755 | Clothing | $69.93 | 105 | ★ 2.9 | 86 | BULK-5d5ddb5f |
| 17075 | Bulk Product 91015eba | Home & Garden | $402.59 | 365 | ★ 1.7 | 41 | BULK-4f5a22b4 |
| 17076 | Bulk Product 6fcc7d4a | Sports & Outdoors | $465.77 | 469 | ★ 4.7 | 48 | BULK-a3dc90df |
| 17077 | Bulk Product 04917059 | Books | $974.98 | 188 | ★ 4.6 | 18 | BULK-200a21a2 |
| 17078 | Bulk Product 21f7e4b6 | Books | $995.27 | 341 | ★ 4.3 | 60 | BULK-8153a2c7 |
| 17079 | Bulk Product d48c6f57 | Clothing | $259.56 | 69 | ★ 2.7 | 92 | BULK-35148fcc |
| 17080 | Bulk Product 1a181f31 | Clothing | $716.06 | 66 | ★ 2.4 | 72 | BULK-44b6b2f6 |
| 17081 | Bulk Product 61b0859c | Sports & Outdoors | $616.75 | 155 | ★ 2.8 | 47 | BULK-6a6af831 |
| 17082 | Bulk Product cfac39ff | Sports & Outdoors | $753.74 | 355 | ★ 3.4 | 33 | BULK-a9827ba1 |
| 17083 | Bulk Product 71cbbaec | Clothing | $102.95 | 29 | ★ 2.6 | 50 | BULK-971be53c |
| 17084 | Bulk Product b9ed0980 | Toys & Games | $900.11 | 302 | ★ 3.2 | 90 | BULK-947ab222 |
// 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
};
}