Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 10935 | Bulk Product aa7db9eb | Sports & Outdoors | $936.45 | 416 | ★ 0.9 | 93 | BULK-edf748f5 |
| 10936 | Bulk Product 09a11f8a | Home & Garden | $292.61 | 342 | ★ 0.1 | 65 | BULK-37ad93ab |
| 10937 | Bulk Product 2c64533e | Clothing | $419.41 | 83 | ★ 3.6 | 85 | BULK-3308badf |
| 10938 | Bulk Product 854a48e1 | Books | $496.19 | 327 | ★ 2.4 | 44 | BULK-062d3465 |
| 10939 | Bulk Product 93c25003 | Home & Garden | $801.37 | 295 | ★ 4.5 | 27 | BULK-b3194b15 |
| 10940 | Bulk Product 5c3e2c37 | Books | $604.08 | 216 | ★ 4.9 | 56 | BULK-a7985e9c |
| 10941 | Bulk Product 9c9b2674 | Home & Garden | $535.75 | 297 | ★ 1.1 | 36 | BULK-a2522b64 |
| 10942 | Bulk Product 18c64b37 | Electronics | $792.00 | 143 | ★ 4.1 | 77 | BULK-b9998cd0 |
| 10943 | Bulk Product 8c8db427 | Clothing | $712.84 | 66 | ★ 1.7 | 98 | BULK-a957fa44 |
| 10944 | Bulk Product c7b4b25e | Electronics | $899.87 | 105 | ★ 0.9 | 42 | BULK-517dd98e |
| 10945 | Bulk Product 9a3f4972 | Sports & Outdoors | $998.35 | 325 | ★ 4.2 | 94 | BULK-cfc0df57 |
| 10946 | Bulk Product b6f5ca6f | Books | $33.44 | 131 | ★ 0.6 | 60 | BULK-7fe427cd |
| 10947 | Bulk Product c0dd2008 | Toys & Games | $355.85 | 9 | ★ 1.0 | 72 | BULK-c7c26903 |
| 10948 | Bulk Product 48e28ad5 | Clothing | $574.08 | 162 | ★ 1.1 | 20 | BULK-08cc52b9 |
| 10949 | Bulk Product f0122027 | Books | $810.71 | 418 | ★ 0.6 | 66 | BULK-cf4e6a36 |
| 10950 | Bulk Product 5ad79eb4 | Books | $523.05 | 70 | ★ 1.0 | 80 | BULK-ec2e751f |
| 10951 | Bulk Product 2bf3a3ef | Home & Garden | $235.68 | 165 | ★ 4.8 | 28 | BULK-3726da55 |
| 10952 | Bulk Product 6c6f14d5 | Electronics | $751.04 | 201 | ★ 1.0 | 55 | BULK-b07c9526 |
| 10953 | Bulk Product 8aae5334 | Electronics | $713.26 | 36 | ★ 0.5 | 25 | BULK-cf88e76d |
| 10954 | Bulk Product c47d0050 | Sports & Outdoors | $165.42 | 188 | ★ 1.8 | 9 | BULK-5c9cafbe |
| 10955 | Bulk Product 749785b5 | Clothing | $392.89 | 20 | ★ 1.9 | 58 | BULK-2010c586 |
| 10956 | Bulk Product 6c809abf | Books | $556.62 | 271 | ★ 4.8 | 83 | BULK-43e5b8ac |
| 10957 | Bulk Product 351f92a3 | Sports & Outdoors | $567.77 | 108 | ★ 0.7 | 56 | BULK-bcc300b8 |
| 10958 | Bulk Product 722d3ea9 | Books | $268.80 | 256 | ★ 0.4 | 6 | BULK-67f0df60 |
| 10959 | Bulk Product 159734ba | Home & Garden | $501.61 | 427 | ★ 1.4 | 20 | BULK-afe0543e |
// 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
};
}