Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 5910 | Bulk Product 2018add3 | Toys & Games | $773.60 | 131 | ★ 3.9 | 99 | BULK-c33b0f7e |
| 5911 | Bulk Product 1bc50eb5 | Sports & Outdoors | $676.75 | 147 | ★ 0.1 | 22 | BULK-10970833 |
| 5912 | Bulk Product b01d3a96 | Books | $15.33 | 59 | ★ 0.0 | 75 | BULK-9ecfcc5d |
| 5913 | Bulk Product 2984bc91 | Electronics | $609.29 | 139 | ★ 3.5 | 65 | BULK-79b1c3b2 |
| 5914 | Bulk Product 87ef0e49 | Clothing | $894.65 | 20 | ★ 0.4 | 8 | BULK-8c9f83c0 |
| 5915 | Bulk Product dae9f0af | Electronics | $580.04 | 21 | ★ 1.9 | 82 | BULK-eb935de2 |
| 5916 | Bulk Product 39cf951d | Toys & Games | $887.92 | 491 | ★ 1.7 | 96 | BULK-f6efbddc |
| 5917 | Bulk Product 338d2e52 | Sports & Outdoors | $204.84 | 231 | ★ 3.7 | 14 | BULK-d444d81d |
| 5918 | Bulk Product 99763a2c | Toys & Games | $796.00 | 12 | ★ 4.5 | 2 | BULK-62e4899d |
| 5919 | Bulk Product 477ff7eb | Electronics | $753.64 | 107 | ★ 3.0 | 39 | BULK-ec8b8a45 |
| 5920 | Bulk Product 2103ecf3 | Clothing | $806.93 | 119 | ★ 1.5 | 77 | BULK-bddce69b |
| 5921 | Bulk Product df876d21 | Electronics | $539.77 | 202 | ★ 2.3 | 28 | BULK-d0d6258f |
| 5922 | Bulk Product 9e1d2f61 | Toys & Games | $821.35 | 474 | ★ 4.4 | 20 | BULK-9d3046db |
| 5923 | Bulk Product abd5f400 | Sports & Outdoors | $837.59 | 169 | ★ 4.2 | 28 | BULK-facdb622 |
| 5924 | Bulk Product 6fe543c5 | Toys & Games | $734.31 | 487 | ★ 2.0 | 5 | BULK-01cc4d9e |
| 5925 | Bulk Product 176ab8fc | Sports & Outdoors | $180.61 | 94 | ★ 0.4 | 13 | BULK-713e2a2f |
| 5926 | Bulk Product 59063744 | Toys & Games | $579.76 | 415 | ★ 0.3 | 11 | BULK-5b9bc260 |
| 5927 | Bulk Product 753b692f | Clothing | $933.79 | 393 | ★ 4.7 | 86 | BULK-dbd8cb95 |
| 5928 | Bulk Product 6323628e | Electronics | $419.76 | 229 | ★ 4.7 | 48 | BULK-84ef1576 |
| 5929 | Bulk Product 00881515 | Toys & Games | $757.33 | 162 | ★ 2.8 | 82 | BULK-09e815d8 |
| 5930 | Bulk Product a8e0a06f | Home & Garden | $996.92 | 160 | ★ 1.0 | 83 | BULK-c02348ce |
| 5931 | Bulk Product ccd4fc6e | Toys & Games | $957.54 | 328 | ★ 1.6 | 46 | BULK-6f0f216a |
| 5932 | Bulk Product 40db2acb | Clothing | $113.01 | 97 | ★ 0.9 | 80 | BULK-010344cd |
| 5933 | Bulk Product fbbbc5b5 | Books | $407.44 | 417 | ★ 4.1 | 97 | BULK-3b65b29b |
| 5934 | Bulk Product 95db2ef3 | Toys & Games | $229.67 | 322 | ★ 0.0 | 47 | BULK-2c726b3a |
// 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
};
}