Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 19185 | Bulk Product b7430574 | Sports & Outdoors | $992.26 | 262 | ★ 4.5 | 83 | BULK-8c95d7cf |
| 19186 | Bulk Product 5e3c58ea | Home & Garden | $610.75 | 75 | ★ 2.3 | 80 | BULK-db0701fa |
| 19187 | Bulk Product 94ff01bc | Books | $910.63 | 59 | ★ 2.7 | 35 | BULK-c978d5f8 |
| 19188 | Bulk Product fd6d1dc4 | Toys & Games | $790.03 | 494 | ★ 2.3 | 51 | BULK-2b324fd9 |
| 19189 | Bulk Product 7e0a73b3 | Electronics | $734.37 | 71 | ★ 4.3 | 5 | BULK-43c38a21 |
| 19190 | Bulk Product 753206e0 | Sports & Outdoors | $946.79 | 292 | ★ 1.1 | 50 | BULK-e5eacf95 |
| 19191 | Bulk Product 2538328a | Sports & Outdoors | $830.20 | 478 | ★ 1.2 | 35 | BULK-fecc1929 |
| 19192 | Bulk Product 29bae616 | Toys & Games | $862.07 | 440 | ★ 2.7 | 13 | BULK-fdcf9784 |
| 19193 | Bulk Product 2dd12470 | Books | $178.78 | 71 | ★ 2.8 | 18 | BULK-d453cf65 |
| 19194 | Bulk Product 1f0ca118 | Clothing | $684.45 | 461 | ★ 2.1 | 52 | BULK-f20b78ab |
| 19195 | Bulk Product 3079654e | Electronics | $214.42 | 8 | ★ 0.3 | 33 | BULK-55f4a9b4 |
| 19196 | Bulk Product 6f3d5e08 | Home & Garden | $509.99 | 363 | ★ 2.2 | 61 | BULK-d3571b1b |
| 19197 | Bulk Product fec6c10e | Home & Garden | $557.51 | 42 | ★ 2.6 | 78 | BULK-44957f31 |
| 19198 | Bulk Product e93a490e | Toys & Games | $494.52 | 315 | ★ 4.4 | 36 | BULK-15f47810 |
| 19199 | Bulk Product d2376d87 | Home & Garden | $29.20 | 482 | ★ 2.9 | 95 | BULK-8b33158d |
| 19200 | Bulk Product 66bcf13f | Sports & Outdoors | $200.38 | 113 | ★ 4.6 | 52 | BULK-2ce089c4 |
| 19201 | Bulk Product 4c1b9998 | Clothing | $387.22 | 303 | ★ 1.6 | 24 | BULK-dfda81b4 |
| 19202 | Bulk Product af42fc4d | Books | $1,009.86 | 147 | ★ 0.6 | 20 | BULK-f3a67fcb |
| 19203 | Bulk Product 02a01954 | Books | $534.41 | 235 | ★ 3.4 | 18 | BULK-be0cfaa3 |
| 19204 | Bulk Product 14fca8fb | Books | $713.19 | 374 | ★ 2.4 | 84 | BULK-e0477495 |
| 19205 | Bulk Product 3c1c9b97 | Books | $183.68 | 13 | ★ 1.2 | 68 | BULK-0f6316d6 |
| 19206 | Bulk Product 74fb5d9e | Sports & Outdoors | $55.66 | 260 | ★ 3.7 | 95 | BULK-f28c161f |
| 19207 | Bulk Product 0ae7379f | Sports & Outdoors | $763.64 | 166 | ★ 2.1 | 2 | BULK-b04d8a33 |
| 19208 | Bulk Product ee198362 | Clothing | $396.30 | 113 | ★ 0.4 | 26 | BULK-6a79c486 |
| 19209 | Bulk Product 2f3d82fc | Clothing | $709.92 | 16 | ★ 1.1 | 53 | BULK-0667e407 |
// 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
};
}