Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 2864 | Mega Clothing Product Plus | Clothing | $745.02 | 39 | ★ 3.1 | 520 | SKU-002864 |
| 2865 | Elite Electronics Product XL | Electronics | $515.39 | 441 | ★ 3.2 | 989 | SKU-002865 |
| 2866 | Elite Sports & Outdoors Product Plus | Sports & Outdoors | $978.30 | 434 | ★ 4.7 | 802 | SKU-002866 |
| 2867 | Deluxe Clothing Product Special Edition | Clothing | $381.07 | 436 | ★ 3.3 | 461 | SKU-002867 |
| 2869 | Ultra Sports & Outdoors Product Plus | Sports & Outdoors | $274.78 | 353 | ★ 3.9 | 782 | SKU-002869 |
| 2870 | Ultra Books Product Pro | Books | $726.02 | 252 | ★ 1.7 | 835 | SKU-002870 |
| 2871 | Deluxe Office Supplies Product Plus | Office Supplies | $509.00 | 192 | ★ 1.1 | 943 | SKU-002871 |
| 2873 | Elite Books Product Pro | Books | $653.00 | 215 | ★ 4.7 | 573 | SKU-002873 |
| 2874 | Premium Electronics Product Classic | Electronics | $209.83 | 63 | ★ 4.4 | 538 | SKU-002874 |
| 2875 | Premium Office Supplies Product Mini | Office Supplies | $25.65 | 408 | ★ 3.2 | 9 | SKU-002875 |
| 2876 | Mega Books Product Mini | Books | $929.75 | 336 | ★ 3.9 | 601 | SKU-002876 |
| 2877 | Pro Automotive Product XL | Automotive | $726.90 | 161 | ★ 3.7 | 216 | SKU-002877 |
| 2878 | Standard Office Supplies Product 2024 | Office Supplies | $941.88 | 100 | ★ 2.2 | 296 | SKU-002878 |
| 2879 | Economy Toys & Games Product Lite | Toys & Games | $980.96 | 307 | ★ 1.2 | 438 | SKU-002879 |
| 2880 | Deluxe Books Product Lite | Books | $215.29 | 283 | ★ 3.7 | 788 | SKU-002880 |
| 2881 | Super Office Supplies Product Pro | Office Supplies | $165.24 | 225 | ★ 2.0 | 323 | SKU-002881 |
| 2882 | Pro Books Product Classic | Books | $977.73 | 375 | ★ 1.1 | 192 | SKU-002882 |
| 2883 | Super Electronics Product Lite | Electronics | $521.61 | 221 | ★ 4.0 | 5 | SKU-002883 |
| 2884 | Pro Office Supplies Product Advanced | Office Supplies | $600.09 | 40 | ★ 3.9 | 860 | SKU-002884 |
| 2885 | Premium Books Product 2024 | Books | $533.95 | 313 | ★ 1.9 | 166 | SKU-002885 |
| 2886 | Ultra Sports & Outdoors Product Special Edition | Sports & Outdoors | $578.76 | 303 | ★ 1.5 | 282 | SKU-002886 |
| 2887 | Mega Automotive Product Pro | Automotive | $876.32 | 446 | ★ 4.9 | 778 | SKU-002887 |
| 2888 | Ultra Office Supplies Product Pro | Office Supplies | $527.09 | 74 | ★ 3.2 | 239 | SKU-002888 |
| 2889 | Deluxe Food & Grocery Product Special Edition | Food & Grocery | $423.11 | 437 | ★ 4.6 | 156 | SKU-002889 |
| 2890 | Economy Health & Beauty Product Mini | Health & Beauty | $748.88 | 163 | ★ 3.4 | 422 | SKU-002890 |
// 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
};
}