Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 3083 | Standard Automotive Product Plus | Automotive | $119.95 | 102 | ★ 1.1 | 644 | SKU-003083 |
| 3084 | Standard Sports & Outdoors Product Pro | Sports & Outdoors | $462.01 | 327 | ★ 1.4 | 951 | SKU-003084 |
| 3085 | Standard Automotive Product Plus | Automotive | $807.00 | 175 | ★ 2.4 | 287 | SKU-003085 |
| 3086 | Super Automotive Product Advanced | Automotive | $278.40 | 363 | ★ 3.1 | 845 | SKU-003086 |
| 3087 | Professional Sports & Outdoors Product Plus | Sports & Outdoors | $94.70 | 44 | ★ 4.6 | 142 | SKU-003087 |
| 3088 | Premium Office Supplies Product Special Edition | Office Supplies | $506.51 | 487 | ★ 2.2 | 739 | SKU-003088 |
| 3089 | Economy Clothing Product Plus | Clothing | $25.78 | 277 | ★ 3.2 | 227 | SKU-003089 |
| 3090 | Economy Books Product Plus | Books | $692.82 | 237 | ★ 1.6 | 936 | SKU-003090 |
| 3091 | Economy Home & Garden Product Classic | Home & Garden | $783.50 | 132 | ★ 4.8 | 918 | SKU-003091 |
| 3092 | Deluxe Electronics Product Max | Electronics | $680.91 | 384 | ★ 3.1 | 880 | SKU-003092 |
| 3093 | Professional Electronics Product Classic | Electronics | $438.48 | 466 | ★ 3.2 | 908 | SKU-003093 |
| 3094 | Standard Sports & Outdoors Product Pro | Sports & Outdoors | $307.66 | 44 | ★ 1.3 | 716 | SKU-003094 |
| 3095 | Elite Food & Grocery Product XL | Food & Grocery | $194.48 | 42 | ★ 2.6 | 993 | SKU-003095 |
| 3097 | Mega Sports & Outdoors Product Classic | Sports & Outdoors | $55.73 | 71 | ★ 4.3 | 198 | SKU-003097 |
| 3098 | Mega Office Supplies Product Lite | Office Supplies | $234.04 | 342 | ★ 1.1 | 862 | SKU-003098 |
| 3099 | Ultra Sports & Outdoors Product Special Edition | Sports & Outdoors | $86.25 | 388 | ★ 3.1 | 562 | SKU-003099 |
| 3100 | Mega Automotive Product Lite | Automotive | $513.07 | 95 | ★ 4.1 | 387 | SKU-003100 |
| 3102 | Economy Health & Beauty Product Mini | Health & Beauty | $657.67 | 6 | ★ 3.8 | 112 | SKU-003102 |
| 3103 | Ultra Food & Grocery Product XL | Food & Grocery | $372.72 | 138 | ★ 3.0 | 467 | SKU-003103 |
| 3104 | Premium Electronics Product 2024 | Electronics | $261.30 | 207 | ★ 1.9 | 582 | SKU-003104 |
| 3105 | Elite Sports & Outdoors Product Special Edition | Sports & Outdoors | $655.04 | 49 | ★ 3.5 | 226 | SKU-003105 |
| 3106 | Professional Health & Beauty Product Classic | Health & Beauty | $698.56 | 226 | ★ 2.0 | 688 | SKU-003106 |
| 3107 | Mega Health & Beauty Product Advanced | Health & Beauty | $945.70 | 425 | ★ 1.3 | 887 | SKU-003107 |
| 3108 | Elite Automotive Product Classic | Automotive | $242.57 | 82 | ★ 2.3 | 481 | SKU-003108 |
| 3109 | Super Office Supplies Product Mini | Office Supplies | $46.35 | 170 | ★ 3.2 | 87 | SKU-003109 |
// 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
};
}