Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 23235 | Bulk Product 332f0611 | Sports & Outdoors | $229.20 | 23 | ★ 2.5 | 47 | BULK-107af8e3 |
| 23236 | Bulk Product 411317cb | Toys & Games | $584.70 | 214 | ★ 4.8 | 57 | BULK-28b2b758 |
| 23237 | Bulk Product 3f9a2df4 | Electronics | $797.48 | 68 | ★ 4.0 | 17 | BULK-8bb7223c |
| 23238 | Bulk Product 3f585024 | Home & Garden | $350.23 | 387 | ★ 3.3 | 76 | BULK-0697cf04 |
| 23239 | Bulk Product 3b72d7b0 | Books | $389.44 | 285 | ★ 3.0 | 69 | BULK-e32715f1 |
| 23240 | Bulk Product b927e538 | Home & Garden | $837.14 | 129 | ★ 3.5 | 61 | BULK-7ada7300 |
| 23241 | Bulk Product 2562a2f6 | Toys & Games | $135.50 | 351 | ★ 2.3 | 70 | BULK-f6151e99 |
| 23242 | Bulk Product 0123d834 | Sports & Outdoors | $627.09 | 499 | ★ 0.5 | 86 | BULK-bed57a1b |
| 23243 | Bulk Product 5adba57a | Clothing | $595.31 | 58 | ★ 2.7 | 21 | BULK-b3b053b4 |
| 23244 | Bulk Product 52b740a0 | Toys & Games | $499.56 | 350 | ★ 4.2 | 55 | BULK-b03b107a |
| 23245 | Bulk Product bb1f6671 | Books | $367.91 | 457 | ★ 4.5 | 81 | BULK-c21a5ef6 |
| 23246 | Bulk Product 3e1fe62c | Books | $181.19 | 248 | ★ 2.3 | 22 | BULK-38702fb9 |
| 23247 | Bulk Product d19ee2f5 | Clothing | $79.49 | 464 | ★ 2.3 | 24 | BULK-c76442e2 |
| 23248 | Bulk Product 20fa07c4 | Home & Garden | $795.31 | 140 | ★ 3.6 | 91 | BULK-3944aa46 |
| 23249 | Bulk Product 51dc8b5f | Books | $624.46 | 68 | ★ 2.7 | 10 | BULK-48cce0ff |
| 23250 | Bulk Product db25ce35 | Books | $904.16 | 74 | ★ 0.2 | 13 | BULK-917cee14 |
| 23251 | Bulk Product 8a513d3e | Sports & Outdoors | $671.58 | 373 | ★ 2.0 | 0 | BULK-2d00689a |
| 23252 | Bulk Product 53de16da | Electronics | $101.30 | 68 | ★ 1.8 | 94 | BULK-101f9795 |
| 23253 | Bulk Product 97c2f9bb | Clothing | $367.69 | 441 | ★ 0.7 | 98 | BULK-c49f65aa |
| 23254 | Bulk Product b79a53a4 | Toys & Games | $384.44 | 95 | ★ 0.2 | 75 | BULK-f73aa477 |
| 23255 | Bulk Product 66a800dd | Clothing | $651.10 | 372 | ★ 3.7 | 82 | BULK-12edf2f7 |
| 23256 | Bulk Product d7f357d3 | Electronics | $340.75 | 83 | ★ 4.9 | 21 | BULK-0bb82f99 |
| 23257 | Bulk Product 285db5a6 | Home & Garden | $817.92 | 285 | ★ 0.7 | 31 | BULK-fbee9bda |
| 23258 | Bulk Product 479b7c52 | Electronics | $578.53 | 239 | ★ 4.7 | 41 | BULK-02456587 |
| 23259 | Bulk Product 4825325f | Sports & Outdoors | $988.34 | 326 | ★ 1.0 | 58 | BULK-a1cbba10 |
// 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
};
}