Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 4901 | Mega Food & Grocery Product Mini | Food & Grocery | $664.56 | 150 | ★ 2.9 | 436 | SKU-004901 |
| 4902 | Super Office Supplies Product Mini | Office Supplies | $720.19 | 306 | ★ 2.1 | 26 | SKU-004902 |
| 4903 | Deluxe Automotive Product Lite | Automotive | $161.26 | 378 | ★ 3.3 | 861 | SKU-004903 |
| 4905 | Elite Electronics Product Mini | Electronics | $789.65 | 323 | ★ 1.1 | 153 | SKU-004905 |
| 4907 | Super Office Supplies Product Classic | Office Supplies | $936.25 | 410 | ★ 3.7 | 510 | SKU-004907 |
| 4908 | Elite Food & Grocery Product Lite | Food & Grocery | $516.45 | 355 | ★ 2.3 | 416 | SKU-004908 |
| 4909 | Ultra Toys & Games Product XL | Toys & Games | $57.72 | 390 | ★ 2.4 | 643 | SKU-004909 |
| 4910 | Economy Clothing Product Classic | Clothing | $208.49 | 390 | ★ 4.1 | 244 | SKU-004910 |
| 4911 | Elite Books Product Advanced | Books | $987.45 | 382 | ★ 2.2 | 113 | SKU-004911 |
| 4912 | Premium Health & Beauty Product 2024 | Health & Beauty | $818.56 | 124 | ★ 1.8 | 624 | SKU-004912 |
| 4913 | Elite Electronics Product 2024 | Electronics | $991.80 | 44 | ★ 3.3 | 623 | SKU-004913 |
| 4914 | Economy Clothing Product Mini | Clothing | $814.89 | 109 | ★ 2.4 | 289 | SKU-004914 |
| 4915 | Super Office Supplies Product Classic | Office Supplies | $924.22 | 291 | ★ 3.6 | 800 | SKU-004915 |
| 4916 | Pro Electronics Product Plus | Electronics | $220.28 | 51 | ★ 2.3 | 499 | SKU-004916 |
| 4917 | Premium Food & Grocery Product Advanced | Food & Grocery | $482.90 | 182 | ★ 4.0 | 629 | SKU-004917 |
| 4918 | Standard Sports & Outdoors Product Advanced | Sports & Outdoors | $256.09 | 320 | ★ 2.2 | 446 | SKU-004918 |
| 4921 | Ultra Food & Grocery Product Lite | Food & Grocery | $589.57 | 299 | ★ 4.6 | 910 | SKU-004921 |
| 4922 | Pro Food & Grocery Product Lite | Food & Grocery | $815.88 | 32 | ★ 1.8 | 636 | SKU-004922 |
| 4923 | Pro Sports & Outdoors Product Max | Sports & Outdoors | $467.43 | 352 | ★ 1.8 | 868 | SKU-004923 |
| 4924 | Professional Clothing Product Lite | Clothing | $338.95 | 48 | ★ 2.0 | 883 | SKU-004924 |
| 4925 | Elite Clothing Product 2024 | Clothing | $493.27 | 455 | ★ 4.3 | 569 | SKU-004925 |
| 4926 | Pro Home & Garden Product Lite | Home & Garden | $952.21 | 379 | ★ 2.1 | 394 | SKU-004926 |
| 4927 | Ultra Clothing Product 2024 | Clothing | $80.57 | 498 | ★ 3.1 | 995 | SKU-004927 |
| 4928 | Pro Toys & Games Product Advanced | Toys & Games | $130.81 | 348 | ★ 2.0 | 687 | SKU-004928 |
| 4929 | Elite Home & Garden Product Classic | Home & Garden | $25.84 | 474 | ★ 1.2 | 131 | SKU-004929 |
| 4930 | Elite Food & Grocery Product 2024 | Food & Grocery | $217.76 | 414 | ★ 1.5 | 677 | SKU-004930 |
| 4931 | Pro Books Product Lite | Books | $97.50 | 238 | ★ 1.8 | 312 | SKU-004931 |
| 4932 | Elite Food & Grocery Product Pro | Food & Grocery | $107.14 | 462 | ★ 2.0 | 916 | SKU-004932 |
| 4933 | Mega Books Product Classic | Books | $231.24 | 251 | ★ 4.7 | 715 | SKU-004933 |
| 4935 | Premium Clothing Product Advanced | Clothing | $202.58 | 93 | ★ 2.0 | 3 | SKU-004935 |
| 4936 | Economy Food & Grocery Product XL | Food & Grocery | $965.37 | 326 | ★ 1.4 | 919 | SKU-004936 |
| 4937 | Economy Sports & Outdoors Product Plus | Sports & Outdoors | $273.92 | 110 | ★ 1.2 | 655 | SKU-004937 |
| 4938 | Deluxe Sports & Outdoors Product Lite | Sports & Outdoors | $351.75 | 18 | ★ 2.6 | 678 | SKU-004938 |
| 4939 | Super Health & Beauty Product Plus | Health & Beauty | $840.62 | 442 | ★ 1.7 | 674 | SKU-004939 |
| 4940 | Super Electronics Product Mini | Electronics | $49.56 | 489 | ★ 3.7 | 649 | SKU-004940 |
| 4941 | Elite Clothing Product 2024 | Clothing | $517.32 | 375 | ★ 1.3 | 249 | SKU-004941 |
| 4942 | Professional Office Supplies Product 2024 | Office Supplies | $185.98 | 75 | ★ 4.2 | 351 | SKU-004942 |
| 4943 | Ultra Food & Grocery Product Pro | Food & Grocery | $242.32 | 225 | ★ 1.8 | 486 | SKU-004943 |
| 4944 | Standard Automotive Product Advanced | Automotive | $154.03 | 443 | ★ 2.6 | 992 | SKU-004944 |
| 4945 | Ultra Sports & Outdoors Product Lite | Sports & Outdoors | $33.69 | 437 | ★ 2.5 | 157 | SKU-004945 |
| 4946 | Economy Sports & Outdoors Product Advanced | Sports & Outdoors | $774.50 | 400 | ★ 4.8 | 614 | SKU-004946 |
| 4947 | Standard Automotive Product Advanced | Automotive | $669.31 | 269 | ★ 3.4 | 483 | SKU-004947 |
| 4948 | Economy Automotive Product Plus | Automotive | $884.30 | 330 | ★ 1.2 | 718 | SKU-004948 |
| 4949 | Super Clothing Product Classic | Clothing | $553.61 | 74 | ★ 3.5 | 259 | SKU-004949 |
| 4950 | Mega Home & Garden Product 2024 | Home & Garden | $416.11 | 96 | ★ 2.2 | 387 | SKU-004950 |
| 4951 | Standard Health & Beauty Product Lite | Health & Beauty | $165.16 | 21 | ★ 1.6 | 872 | SKU-004951 |
| 4952 | Pro Books Product Lite | Books | $296.06 | 114 | ★ 1.4 | 350 | SKU-004952 |
| 4954 | Professional Food & Grocery Product 2024 | Food & Grocery | $457.66 | 414 | ★ 2.9 | 45 | SKU-004954 |
| 4955 | Premium Food & Grocery Product Plus | Food & Grocery | $964.73 | 491 | ★ 2.4 | 243 | SKU-004955 |
| 4956 | Deluxe Toys & Games Product Classic | Toys & Games | $596.60 | 218 | ★ 3.8 | 243 | SKU-004956 |
// 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
};
}