Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 4957 | Deluxe Food & Grocery Product 2024 | Food & Grocery | $678.99 | 491 | ★ 3.2 | 205 | SKU-004957 |
| 4958 | Premium Food & Grocery Product Advanced | Food & Grocery | $629.43 | 114 | ★ 4.2 | 600 | SKU-004958 |
| 4959 | Mega Clothing Product Mini | Clothing | $973.57 | 318 | ★ 3.9 | 835 | SKU-004959 |
| 4960 | Standard Books Product 2024 | Books | $336.54 | 343 | ★ 4.2 | 699 | SKU-004960 |
| 4961 | Mega Food & Grocery Product Classic | Food & Grocery | $997.32 | 341 | ★ 3.1 | 617 | SKU-004961 |
| 4962 | Economy Books Product Special Edition | Books | $301.14 | 189 | ★ 3.6 | 352 | SKU-004962 |
| 4963 | Economy Health & Beauty Product Plus | Health & Beauty | $961.91 | 350 | ★ 3.6 | 261 | SKU-004963 |
| 4964 | Premium Books Product Classic | Books | $359.84 | 356 | ★ 1.7 | 386 | SKU-004964 |
| 4965 | Standard Electronics Product Lite | Electronics | $550.59 | 345 | ★ 4.4 | 526 | SKU-004965 |
| 4966 | Professional Health & Beauty Product Special Edition | Health & Beauty | $371.03 | 260 | ★ 4.8 | 769 | SKU-004966 |
| 4967 | Premium Food & Grocery Product 2024 | Food & Grocery | $28.22 | 51 | ★ 3.1 | 143 | SKU-004967 |
| 4968 | Pro Automotive Product Plus | Automotive | $818.90 | 91 | ★ 2.2 | 649 | SKU-004968 |
| 4969 | Pro Food & Grocery Product Classic | Food & Grocery | $615.66 | 369 | ★ 3.3 | 638 | SKU-004969 |
| 4970 | Standard Books Product XL | Books | $908.11 | 290 | ★ 2.4 | 385 | SKU-004970 |
| 4971 | Deluxe Books Product Lite | Books | $386.52 | 69 | ★ 1.8 | 456 | SKU-004971 |
| 4972 | Super Sports & Outdoors Product 2024 | Sports & Outdoors | $836.81 | 76 | ★ 2.2 | 15 | SKU-004972 |
| 4973 | Premium Home & Garden Product Max | Home & Garden | $83.06 | 72 | ★ 3.4 | 801 | SKU-004973 |
| 4974 | Super Sports & Outdoors Product Plus | Sports & Outdoors | $321.24 | 196 | ★ 2.8 | 523 | SKU-004974 |
| 4975 | Elite Books Product 2024 | Books | $23.54 | 403 | ★ 4.8 | 434 | SKU-004975 |
| 4976 | Deluxe Home & Garden Product 2024 | Home & Garden | $137.57 | 461 | ★ 3.8 | 648 | SKU-004976 |
| 4977 | Mega Office Supplies Product Classic | Office Supplies | $876.34 | 49 | ★ 4.8 | 0 | SKU-004977 |
| 4978 | Premium Toys & Games Product Classic | Toys & Games | $44.01 | 316 | ★ 4.8 | 422 | SKU-004978 |
| 4979 | Professional Food & Grocery Product 2024 | Food & Grocery | $823.63 | 332 | ★ 2.6 | 192 | SKU-004979 |
| 4981 | Mega Home & Garden Product Advanced | Home & Garden | $422.13 | 292 | ★ 4.0 | 180 | SKU-004981 |
| 4982 | Ultra Office Supplies Product Plus | Office Supplies | $760.59 | 470 | ★ 2.8 | 869 | SKU-004982 |
| 4983 | Mega Automotive Product 2024 | Automotive | $256.11 | 473 | ★ 4.8 | 338 | SKU-004983 |
| 4984 | Standard Clothing Product Max | Clothing | $794.18 | 291 | ★ 3.3 | 474 | SKU-004984 |
| 4985 | Deluxe Health & Beauty Product Lite | Health & Beauty | $457.04 | 394 | ★ 2.9 | 254 | SKU-004985 |
| 4986 | Deluxe Health & Beauty Product XL | Health & Beauty | $195.69 | 384 | ★ 4.3 | 309 | SKU-004986 |
| 4988 | Premium Home & Garden Product Lite | Home & Garden | $747.57 | 152 | ★ 3.6 | 996 | SKU-004988 |
| 4989 | Super Clothing Product Special Edition | Clothing | $397.58 | 219 | ★ 3.2 | 76 | SKU-004989 |
| 4990 | Elite Home & Garden Product Max | Home & Garden | $164.57 | 472 | ★ 4.4 | 748 | SKU-004990 |
| 4991 | Pro Clothing Product Max | Clothing | $747.23 | 413 | ★ 4.0 | 547 | SKU-004991 |
| 4992 | Elite Toys & Games Product Mini | Toys & Games | $846.85 | 364 | ★ 3.0 | 685 | SKU-004992 |
| 4993 | Economy Food & Grocery Product 2024 | Food & Grocery | $926.32 | 26 | ★ 1.8 | 161 | SKU-004993 |
| 4994 | Elite Clothing Product XL | Clothing | $778.59 | 352 | ★ 4.3 | 410 | SKU-004994 |
| 4995 | Economy Toys & Games Product Pro | Toys & Games | $306.07 | 6 | ★ 4.4 | 797 | SKU-004995 |
| 4997 | Elite Home & Garden Product Advanced | Home & Garden | $89.35 | 383 | ★ 2.2 | 476 | SKU-004997 |
| 4998 | Standard Automotive Product Mini | Automotive | $618.16 | 289 | ★ 3.3 | 46 | SKU-004998 |
| 4999 | Economy Clothing Product 2024 | Clothing | $818.87 | 486 | ★ 2.0 | 691 | SKU-004999 |
| 5000 | Super Clothing Product 2024 | Clothing | $795.44 | 93 | ★ 1.5 | 350 | SKU-005000 |
| 5001 | Bulk Product 45ac2598 | Toys & Games | $809.37 | 149 | ★ 2.5 | 97 | BULK-638cf492 |
| 5002 | Bulk Product 86c5c2e3 | Toys & Games | $59.60 | 193 | ★ 0.9 | 64 | BULK-a5a0235c |
| 5003 | Bulk Product 8dfb22ae | Books | $496.89 | 286 | ★ 2.6 | 47 | BULK-2c846444 |
| 5004 | Bulk Product d6974228 | Sports & Outdoors | $997.50 | 461 | ★ 3.3 | 58 | BULK-70607953 |
| 5005 | Bulk Product 748791d0 | Home & Garden | $574.00 | 98 | ★ 0.6 | 30 | BULK-50cc55e9 |
| 5006 | Bulk Product 6ac5ae54 | Books | $612.99 | 157 | ★ 1.4 | 85 | BULK-7bad3a7c |
| 5007 | Bulk Product 9545d593 | Books | $95.51 | 339 | ★ 0.4 | 63 | BULK-352608e3 |
| 5008 | Bulk Product f1d95d26 | Clothing | $160.61 | 144 | ★ 3.6 | 9 | BULK-9bffeda3 |
| 5009 | Bulk Product 87e5902f | Clothing | $158.02 | 461 | ★ 4.9 | 32 | BULK-1e3d48b5 |
// 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
};
}