Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 11535 | Bulk Product 153dba44 | Clothing | $465.44 | 384 | ★ 4.7 | 15 | BULK-4a676a0b |
| 11536 | Bulk Product 1210711f | Toys & Games | $479.49 | 50 | ★ 3.5 | 26 | BULK-c8c37fdd |
| 11537 | Bulk Product e88fcfde | Electronics | $163.07 | 317 | ★ 4.8 | 22 | BULK-cb2b85df |
| 11538 | Bulk Product 5d01e9ba | Toys & Games | $135.28 | 243 | ★ 1.0 | 51 | BULK-99746072 |
| 11539 | Bulk Product 7fcd8a74 | Electronics | $465.72 | 172 | ★ 1.5 | 28 | BULK-3ef8ddb2 |
| 11540 | Bulk Product 507f0e68 | Sports & Outdoors | $437.53 | 90 | ★ 0.3 | 23 | BULK-ac3cdb6f |
| 11541 | Bulk Product 8491093b | Toys & Games | $219.07 | 225 | ★ 4.3 | 80 | BULK-a9e117bd |
| 11542 | Bulk Product e1fe8f1e | Home & Garden | $41.68 | 198 | ★ 3.2 | 45 | BULK-7197fb13 |
| 11543 | Bulk Product f1cc88a0 | Books | $108.07 | 423 | ★ 1.0 | 92 | BULK-05822b75 |
| 11544 | Bulk Product 5a9e8b2d | Books | $395.38 | 236 | ★ 0.2 | 91 | BULK-7b8be661 |
| 11545 | Bulk Product f9429161 | Sports & Outdoors | $1,004.19 | 156 | ★ 1.5 | 59 | BULK-0d1e889a |
| 11546 | Bulk Product 03af3846 | Home & Garden | $145.37 | 201 | ★ 3.8 | 2 | BULK-613967e4 |
| 11547 | Bulk Product c6591140 | Home & Garden | $838.35 | 401 | ★ 3.2 | 97 | BULK-5c9d38e7 |
| 11548 | Bulk Product 505d05a5 | Clothing | $282.01 | 245 | ★ 1.4 | 51 | BULK-1942a507 |
| 11549 | Bulk Product 0257aa1f | Books | $49.55 | 408 | ★ 3.7 | 41 | BULK-d4f5514e |
| 11550 | Bulk Product 011187a9 | Toys & Games | $149.97 | 367 | ★ 3.5 | 99 | BULK-4a041f4b |
| 11551 | Bulk Product e77d2195 | Clothing | $925.36 | 351 | ★ 0.1 | 59 | BULK-8c2a6c53 |
| 11552 | Bulk Product e2db26c5 | Electronics | $825.18 | 141 | ★ 3.4 | 91 | BULK-40c817e3 |
| 11553 | Bulk Product f3621e6f | Home & Garden | $970.80 | 80 | ★ 1.6 | 48 | BULK-13b00936 |
| 11554 | Bulk Product f94ed003 | Toys & Games | $425.24 | 107 | ★ 0.5 | 69 | BULK-ced30154 |
| 11555 | Bulk Product 9ab0ab33 | Sports & Outdoors | $929.54 | 223 | ★ 4.5 | 37 | BULK-108a2af4 |
| 11556 | Bulk Product 35d09e50 | Home & Garden | $720.71 | 316 | ★ 0.2 | 29 | BULK-8e9c4b04 |
| 11557 | Bulk Product e214f5f7 | Sports & Outdoors | $183.23 | 483 | ★ 0.1 | 47 | BULK-1b03df95 |
| 11558 | Bulk Product fff16354 | Books | $726.24 | 440 | ★ 4.7 | 66 | BULK-138c1bc9 |
| 11559 | Bulk Product 3fb8d99b | Toys & Games | $744.07 | 118 | ★ 3.2 | 32 | BULK-34329fcf |
// 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
};
}