Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 17035 | Bulk Product 51352dce | Home & Garden | $931.18 | 145 | ★ 4.8 | 15 | BULK-cc5f6e4c |
| 17036 | Bulk Product 41bb0033 | Electronics | $153.29 | 281 | ★ 4.0 | 24 | BULK-1eae25dd |
| 17037 | Bulk Product 7d3eb6c5 | Electronics | $97.07 | 200 | ★ 0.7 | 99 | BULK-dbe39558 |
| 17038 | Bulk Product 5c76339d | Home & Garden | $888.08 | 412 | ★ 2.3 | 82 | BULK-60d52633 |
| 17039 | Bulk Product 7229f5fa | Electronics | $94.31 | 499 | ★ 3.0 | 43 | BULK-c4e64b59 |
| 17040 | Bulk Product 06871ff8 | Sports & Outdoors | $246.32 | 425 | ★ 0.6 | 84 | BULK-90da6a98 |
| 17041 | Bulk Product 5ae0ec78 | Clothing | $805.09 | 0 | ★ 3.6 | 71 | BULK-9a3ce5b7 |
| 17042 | Bulk Product 1fc85536 | Books | $800.52 | 360 | ★ 3.3 | 61 | BULK-aa30f1b5 |
| 17043 | Bulk Product ef5cc9f6 | Electronics | $355.73 | 159 | ★ 0.4 | 74 | BULK-fea82082 |
| 17044 | Bulk Product f3a0ad06 | Sports & Outdoors | $707.78 | 344 | ★ 3.0 | 8 | BULK-5e8ffbb7 |
| 17045 | Bulk Product 47f25e78 | Clothing | $394.24 | 491 | ★ 1.4 | 44 | BULK-1d43e64e |
| 17046 | Bulk Product be056218 | Electronics | $157.75 | 210 | ★ 1.8 | 47 | BULK-b85626b9 |
| 17047 | Bulk Product 082b490b | Toys & Games | $324.21 | 323 | ★ 2.1 | 18 | BULK-65fe5710 |
| 17048 | Bulk Product e647c6e1 | Home & Garden | $434.52 | 475 | ★ 2.1 | 48 | BULK-0169a745 |
| 17049 | Bulk Product bbd7d97b | Sports & Outdoors | $629.61 | 311 | ★ 2.6 | 49 | BULK-a45ef521 |
| 17050 | Bulk Product f04527d4 | Toys & Games | $274.91 | 377 | ★ 0.8 | 55 | BULK-0ff12ee2 |
| 17051 | Bulk Product dfa48f06 | Sports & Outdoors | $906.20 | 311 | ★ 0.8 | 90 | BULK-048b18f2 |
| 17052 | Bulk Product 0f508afc | Clothing | $954.80 | 490 | ★ 4.6 | 37 | BULK-b0aeef15 |
| 17053 | Bulk Product f2e54c5e | Books | $219.97 | 291 | ★ 2.4 | 82 | BULK-31a3696a |
| 17054 | Bulk Product 62fc9891 | Toys & Games | $483.18 | 23 | ★ 4.4 | 16 | BULK-df344bc6 |
| 17055 | Bulk Product 8d2be23a | Electronics | $61.46 | 83 | ★ 2.9 | 24 | BULK-e44e43db |
| 17056 | Bulk Product 21bc1daa | Toys & Games | $844.96 | 382 | ★ 3.3 | 80 | BULK-88c0b73a |
| 17057 | Bulk Product 00131a6e | Clothing | $385.86 | 429 | ★ 1.6 | 5 | BULK-17bcc99f |
| 17058 | Bulk Product bfa7a7a9 | Clothing | $344.54 | 202 | ★ 0.1 | 35 | BULK-d1cb5185 |
| 17059 | Bulk Product dc559679 | Home & Garden | $88.75 | 418 | ★ 3.1 | 78 | BULK-ddc9ed1f |
// 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
};
}