Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 783 | Mega Health & Beauty Product Lite | Health & Beauty | $219.58 | 485 | ★ 2.8 | 226 | SKU-000783 |
| 784 | Ultra Home & Garden Product Classic | Home & Garden | $855.13 | 198 | ★ 1.3 | 784 | SKU-000784 |
| 786 | Standard Home & Garden Product XL | Home & Garden | $546.83 | 379 | ★ 2.2 | 682 | SKU-000786 |
| 787 | Professional Office Supplies Product Max | Office Supplies | $185.32 | 193 | ★ 2.0 | 4 | SKU-000787 |
| 788 | Elite Toys & Games Product Mini | Toys & Games | $807.85 | 218 | ★ 2.5 | 925 | SKU-000788 |
| 789 | Pro Books Product Classic | Books | $124.82 | 287 | ★ 2.8 | 990 | SKU-000789 |
| 790 | Professional Books Product Lite | Books | $755.88 | 56 | ★ 2.0 | 381 | SKU-000790 |
| 791 | Economy Books Product Lite | Books | $25.30 | 468 | ★ 4.3 | 745 | SKU-000791 |
| 792 | Pro Books Product Advanced | Books | $354.79 | 455 | ★ 4.3 | 870 | SKU-000792 |
| 793 | Deluxe Home & Garden Product Max | Home & Garden | $654.85 | 225 | ★ 4.8 | 223 | SKU-000793 |
| 795 | Professional Sports & Outdoors Product Special Edition | Sports & Outdoors | $858.71 | 405 | ★ 1.9 | 814 | SKU-000795 |
| 796 | Mega Toys & Games Product Max | Toys & Games | $28.48 | 455 | ★ 3.0 | 615 | SKU-000796 |
| 797 | Deluxe Books Product Classic | Books | $635.08 | 22 | ★ 4.0 | 810 | SKU-000797 |
| 798 | Professional Health & Beauty Product Plus | Health & Beauty | $49.30 | 339 | ★ 2.2 | 986 | SKU-000798 |
| 799 | Pro Home & Garden Product Lite | Home & Garden | $477.84 | 234 | ★ 4.0 | 322 | SKU-000799 |
| 801 | Premium Clothing Product Classic | Clothing | $121.17 | 57 | ★ 4.8 | 23 | SKU-000801 |
| 802 | Mega Automotive Product Max | Automotive | $819.72 | 162 | ★ 1.3 | 808 | SKU-000802 |
| 804 | Pro Home & Garden Product Plus | Home & Garden | $862.50 | 293 | ★ 3.3 | 409 | SKU-000804 |
| 805 | Mega Books Product Classic | Books | $218.06 | 271 | ★ 4.1 | 244 | SKU-000805 |
| 806 | Super Health & Beauty Product Mini | Health & Beauty | $626.82 | 419 | ★ 3.1 | 854 | SKU-000806 |
| 807 | Super Automotive Product Pro | Automotive | $947.77 | 25 | ★ 3.7 | 998 | SKU-000807 |
| 808 | Economy Electronics Product Special Edition | Electronics | $142.20 | 472 | ★ 2.8 | 811 | SKU-000808 |
| 809 | Elite Toys & Games Product Max | Toys & Games | $22.81 | 200 | ★ 3.2 | 804 | SKU-000809 |
| 810 | Professional Food & Grocery Product Special Edition | Food & Grocery | $53.88 | 190 | ★ 3.0 | 73 | SKU-000810 |
| 811 | Ultra Toys & Games Product Advanced | Toys & Games | $446.85 | 408 | ★ 5.0 | 341 | SKU-000811 |
// 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
};
}