Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 7035 | Bulk Product 093a3953 | Books | $213.24 | 324 | ★ 2.8 | 84 | BULK-5fdc446f |
| 7036 | Bulk Product ed66c31b | Books | $419.98 | 226 | ★ 1.5 | 42 | BULK-0ddd26f0 |
| 7037 | Bulk Product 663aee5d | Books | $565.39 | 271 | ★ 0.4 | 30 | BULK-ce1c2e74 |
| 7038 | Bulk Product dc1cb2ee | Clothing | $603.89 | 107 | ★ 4.2 | 72 | BULK-b84e01ac |
| 7039 | Bulk Product 6055a865 | Books | $236.18 | 81 | ★ 4.0 | 48 | BULK-f9dde938 |
| 7040 | Bulk Product 813ec8f4 | Toys & Games | $456.40 | 178 | ★ 2.6 | 75 | BULK-e6546eb1 |
| 7041 | Bulk Product 95eb1dcc | Books | $886.73 | 319 | ★ 1.1 | 16 | BULK-e64ef980 |
| 7042 | Bulk Product 389efd56 | Books | $594.21 | 149 | ★ 0.2 | 4 | BULK-c182715d |
| 7043 | Bulk Product 343325a5 | Sports & Outdoors | $432.92 | 67 | ★ 4.6 | 99 | BULK-d8d1304e |
| 7044 | Bulk Product 832b4200 | Clothing | $132.12 | 469 | ★ 2.2 | 6 | BULK-6019b3dc |
| 7045 | Bulk Product fd6c1625 | Clothing | $253.73 | 430 | ★ 4.4 | 70 | BULK-add749e2 |
| 7046 | Bulk Product 0783fbc9 | Toys & Games | $239.23 | 31 | ★ 2.3 | 83 | BULK-3392751e |
| 7047 | Bulk Product 08f7ca36 | Sports & Outdoors | $311.39 | 347 | ★ 1.8 | 71 | BULK-8c77cab5 |
| 7048 | Bulk Product 87f00e1b | Toys & Games | $62.13 | 356 | ★ 0.7 | 10 | BULK-0755872d |
| 7049 | Bulk Product f5322b33 | Home & Garden | $961.71 | 216 | ★ 2.5 | 72 | BULK-1a312990 |
| 7050 | Bulk Product 5a6d4c71 | Home & Garden | $122.41 | 183 | ★ 3.2 | 94 | BULK-fa909d56 |
| 7051 | Bulk Product 3b70dfbf | Clothing | $992.77 | 151 | ★ 2.5 | 36 | BULK-c7fa95fb |
| 7052 | Bulk Product 50bb4456 | Sports & Outdoors | $84.05 | 235 | ★ 0.5 | 1 | BULK-45ceebdd |
| 7053 | Bulk Product d6898261 | Electronics | $88.40 | 495 | ★ 4.8 | 19 | BULK-7a8517da |
| 7054 | Bulk Product 855e2c5a | Sports & Outdoors | $750.17 | 367 | ★ 5.0 | 32 | BULK-b7e96312 |
| 7055 | Bulk Product 0e93c343 | Home & Garden | $288.75 | 244 | ★ 4.6 | 44 | BULK-7835eaf1 |
| 7056 | Bulk Product 168ffde7 | Books | $126.73 | 277 | ★ 0.1 | 34 | BULK-4757423e |
| 7057 | Bulk Product fc576b23 | Clothing | $771.95 | 197 | ★ 1.0 | 28 | BULK-877ec87d |
| 7058 | Bulk Product a63a4cc6 | Electronics | $66.72 | 80 | ★ 2.8 | 2 | BULK-02bdfe2a |
| 7059 | Bulk Product b0068baa | Home & Garden | $857.58 | 306 | ★ 1.9 | 7 | BULK-cc87339e |
// 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
};
}