Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 4874 | Economy Books Product XL | Books | $240.14 | 117 | ★ 4.8 | 994 | SKU-004874 |
| 4875 | Pro Sports & Outdoors Product XL | Sports & Outdoors | $825.39 | 449 | ★ 3.4 | 520 | SKU-004875 |
| 4876 | Super Electronics Product Classic | Electronics | $443.59 | 402 | ★ 3.2 | 957 | SKU-004876 |
| 4877 | Elite Food & Grocery Product Special Edition | Food & Grocery | $523.30 | 455 | ★ 2.3 | 276 | SKU-004877 |
| 4878 | Economy Electronics Product Mini | Electronics | $353.37 | 210 | ★ 2.9 | 200 | SKU-004878 |
| 4879 | Professional Home & Garden Product Lite | Home & Garden | $372.83 | 44 | ★ 4.2 | 544 | SKU-004879 |
| 4880 | Elite Food & Grocery Product Lite | Food & Grocery | $131.28 | 32 | ★ 5.0 | 551 | SKU-004880 |
| 4881 | Ultra Office Supplies Product Pro | Office Supplies | $996.38 | 400 | ★ 4.4 | 369 | SKU-004881 |
| 4882 | Super Toys & Games Product 2024 | Toys & Games | $449.04 | 293 | ★ 3.1 | 651 | SKU-004882 |
| 4884 | Mega Toys & Games Product Mini | Toys & Games | $303.34 | 86 | ★ 4.2 | 3 | SKU-004884 |
| 4885 | Super Electronics Product Classic | Electronics | $891.96 | 311 | ★ 2.4 | 100 | SKU-004885 |
| 4886 | Elite Health & Beauty Product Classic | Health & Beauty | $115.58 | 13 | ★ 2.2 | 372 | SKU-004886 |
| 4887 | Elite Home & Garden Product Advanced | Home & Garden | $313.91 | 111 | ★ 2.9 | 304 | SKU-004887 |
| 4888 | Deluxe Office Supplies Product Lite | Office Supplies | $235.46 | 315 | ★ 3.2 | 855 | SKU-004888 |
| 4889 | Standard Clothing Product Advanced | Clothing | $726.44 | 123 | ★ 4.7 | 84 | SKU-004889 |
| 4890 | Elite Books Product Plus | Books | $728.40 | 197 | ★ 4.6 | 533 | SKU-004890 |
| 4891 | Deluxe Electronics Product Plus | Electronics | $284.31 | 428 | ★ 4.7 | 568 | SKU-004891 |
| 4892 | Professional Toys & Games Product Plus | Toys & Games | $159.12 | 136 | ★ 2.2 | 859 | SKU-004892 |
| 4893 | Professional Home & Garden Product XL | Home & Garden | $394.55 | 255 | ★ 3.2 | 892 | SKU-004893 |
| 4894 | Economy Electronics Product Lite | Electronics | $304.52 | 108 | ★ 2.3 | 153 | SKU-004894 |
| 4895 | Super Clothing Product Mini | Clothing | $640.86 | 203 | ★ 3.5 | 602 | SKU-004895 |
| 4897 | Ultra Office Supplies Product Classic | Office Supplies | $360.86 | 3 | ★ 2.3 | 260 | SKU-004897 |
| 4898 | Elite Electronics Product Pro | Electronics | $67.10 | 388 | ★ 4.2 | 672 | SKU-004898 |
| 4899 | Mega Automotive Product 2024 | Automotive | $47.91 | 9 | ★ 3.0 | 54 | SKU-004899 |
| 4900 | Deluxe Home & Garden Product XL | Home & Garden | $331.68 | 346 | ★ 3.9 | 71 | SKU-004900 |
// 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
};
}