Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 18835 | Bulk Product 1998473d | Sports & Outdoors | $923.62 | 389 | ★ 0.3 | 25 | BULK-0e058ffb |
| 18836 | Bulk Product 87e018c0 | Electronics | $140.79 | 23 | ★ 0.6 | 17 | BULK-525e6c1f |
| 18837 | Bulk Product fa02a184 | Toys & Games | $117.98 | 151 | ★ 1.6 | 47 | BULK-ee7e14e0 |
| 18838 | Bulk Product 8e1b2497 | Books | $596.00 | 365 | ★ 4.3 | 27 | BULK-75ec2bb1 |
| 18839 | Bulk Product dfbde4af | Electronics | $167.59 | 258 | ★ 3.5 | 32 | BULK-6bce81da |
| 18840 | Bulk Product 3ce65ab7 | Sports & Outdoors | $598.11 | 49 | ★ 0.3 | 70 | BULK-a6c08290 |
| 18841 | Bulk Product 4518d9ef | Electronics | $753.26 | 247 | ★ 4.8 | 27 | BULK-b1ae03ab |
| 18842 | Bulk Product 7188e787 | Toys & Games | $391.07 | 19 | ★ 0.8 | 65 | BULK-cfe677da |
| 18843 | Bulk Product 93547be2 | Toys & Games | $658.59 | 7 | ★ 3.1 | 58 | BULK-ffd81aee |
| 18844 | Bulk Product efe642ca | Sports & Outdoors | $393.18 | 64 | ★ 4.2 | 34 | BULK-c6581adb |
| 18845 | Bulk Product a61d98fa | Home & Garden | $328.10 | 181 | ★ 0.1 | 44 | BULK-27967b38 |
| 18846 | Bulk Product ba123ef3 | Clothing | $942.16 | 244 | ★ 3.8 | 97 | BULK-dd3aafc3 |
| 18847 | Bulk Product 3ff64745 | Books | $388.05 | 244 | ★ 4.7 | 60 | BULK-d3cb28a1 |
| 18848 | Bulk Product 3d1ef9cb | Electronics | $518.26 | 469 | ★ 4.3 | 89 | BULK-042f1b35 |
| 18849 | Bulk Product f0771b16 | Sports & Outdoors | $675.46 | 135 | ★ 4.1 | 8 | BULK-19d29d17 |
| 18850 | Bulk Product 4bc5f727 | Books | $579.14 | 499 | ★ 1.5 | 78 | BULK-c6045b2b |
| 18851 | Bulk Product e03a001e | Clothing | $489.62 | 281 | ★ 0.5 | 59 | BULK-df161f9b |
| 18852 | Bulk Product 89ba9d9e | Home & Garden | $281.52 | 395 | ★ 4.7 | 80 | BULK-70399e1d |
| 18853 | Bulk Product c02c568c | Toys & Games | $694.18 | 292 | ★ 0.3 | 80 | BULK-ee5154ac |
| 18854 | Bulk Product 4ccbb781 | Sports & Outdoors | $319.38 | 314 | ★ 1.2 | 89 | BULK-d068fb1a |
| 18855 | Bulk Product cafcdaf0 | Clothing | $458.77 | 379 | ★ 4.6 | 77 | BULK-31ab46bf |
| 18856 | Bulk Product ee8f6776 | Books | $28.17 | 187 | ★ 1.3 | 4 | BULK-7b725851 |
| 18857 | Bulk Product 47398c05 | Books | $418.85 | 431 | ★ 0.4 | 39 | BULK-d5e17272 |
| 18858 | Bulk Product 2c6035fa | Sports & Outdoors | $445.03 | 478 | ★ 2.8 | 82 | BULK-902e3467 |
| 18859 | Bulk Product b1e8d10e | Electronics | $628.60 | 363 | ★ 0.3 | 76 | BULK-debd3cec |
// 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
};
}