Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 926 | Elite Toys & Games Product Classic | Toys & Games | $64.80 | 345 | ★ 4.5 | 104 | SKU-000926 |
| 927 | Economy Books Product Mini | Books | $341.15 | 160 | ★ 4.3 | 635 | SKU-000927 |
| 928 | Economy Electronics Product 2024 | Electronics | $615.56 | 95 | ★ 1.4 | 851 | SKU-000928 |
| 929 | Premium Automotive Product Classic | Automotive | $932.99 | 59 | ★ 2.0 | 321 | SKU-000929 |
| 930 | Pro Clothing Product Max | Clothing | $42.18 | 212 | ★ 4.7 | 347 | SKU-000930 |
| 932 | Professional Food & Grocery Product Mini | Food & Grocery | $939.41 | 439 | ★ 1.3 | 23 | SKU-000932 |
| 933 | Professional Electronics Product Classic | Electronics | $522.45 | 398 | ★ 3.8 | 806 | SKU-000933 |
| 935 | Mega Books Product Lite | Books | $650.88 | 418 | ★ 1.7 | 212 | SKU-000935 |
| 936 | Mega Books Product Plus | Books | $239.45 | 9 | ★ 3.2 | 357 | SKU-000936 |
| 937 | Mega Toys & Games Product Pro | Toys & Games | $889.19 | 440 | ★ 3.8 | 32 | SKU-000937 |
| 938 | Professional Home & Garden Product 2024 | Home & Garden | $330.39 | 163 | ★ 1.0 | 851 | SKU-000938 |
| 939 | Economy Automotive Product Mini | Automotive | $330.66 | 36 | ★ 4.8 | 967 | SKU-000939 |
| 940 | Pro Health & Beauty Product 2024 | Health & Beauty | $82.18 | 103 | ★ 2.5 | 960 | SKU-000940 |
| 941 | Economy Office Supplies Product Advanced | Office Supplies | $283.55 | 208 | ★ 3.2 | 363 | SKU-000941 |
| 942 | Mega Home & Garden Product Lite | Home & Garden | $585.28 | 214 | ★ 2.4 | 931 | SKU-000942 |
| 943 | Pro Clothing Product Plus | Clothing | $272.57 | 128 | ★ 4.4 | 419 | SKU-000943 |
| 944 | Super Books Product Plus | Books | $532.47 | 41 | ★ 5.0 | 653 | SKU-000944 |
| 945 | Professional Office Supplies Product 2024 | Office Supplies | $200.76 | 215 | ★ 4.5 | 463 | SKU-000945 |
| 946 | Super Food & Grocery Product Classic | Food & Grocery | $269.46 | 244 | ★ 4.4 | 928 | SKU-000946 |
| 947 | Elite Electronics Product Advanced | Electronics | $883.39 | 31 | ★ 2.3 | 742 | SKU-000947 |
| 948 | Professional Office Supplies Product Advanced | Office Supplies | $153.28 | 96 | ★ 2.9 | 508 | SKU-000948 |
| 949 | Standard Food & Grocery Product Plus | Food & Grocery | $765.52 | 56 | ★ 4.8 | 441 | SKU-000949 |
| 950 | Professional Home & Garden Product Lite | Home & Garden | $272.89 | 37 | ★ 5.0 | 679 | SKU-000950 |
| 951 | Deluxe Books Product Lite | Books | $738.94 | 341 | ★ 3.4 | 469 | SKU-000951 |
| 952 | Mega Books Product Mini | Books | $743.49 | 47 | ★ 2.5 | 929 | SKU-000952 |
// 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
};
}