Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 21035 | Bulk Product 1810200b | Electronics | $579.68 | 93 | ★ 0.7 | 17 | BULK-ad8a98a5 |
| 21036 | Bulk Product b7430473 | Sports & Outdoors | $940.77 | 107 | ★ 4.2 | 23 | BULK-30308624 |
| 21037 | Bulk Product caf43be1 | Toys & Games | $300.98 | 106 | ★ 1.9 | 8 | BULK-8316675e |
| 21038 | Bulk Product 72a1c191 | Clothing | $436.95 | 10 | ★ 3.4 | 65 | BULK-5611659b |
| 21039 | Bulk Product cf86a9cb | Books | $913.10 | 111 | ★ 3.6 | 5 | BULK-9c3fa3c0 |
| 21040 | Bulk Product 5003ba90 | Books | $293.73 | 493 | ★ 2.9 | 93 | BULK-df29ca25 |
| 21041 | Bulk Product a2fcc309 | Sports & Outdoors | $81.62 | 334 | ★ 0.3 | 65 | BULK-e900e5bc |
| 21042 | Bulk Product e3b0be98 | Toys & Games | $870.65 | 378 | ★ 4.3 | 1 | BULK-416e7bf4 |
| 21043 | Bulk Product ed02cabb | Home & Garden | $650.75 | 423 | ★ 0.5 | 9 | BULK-3c85335c |
| 21044 | Bulk Product d17eae45 | Toys & Games | $837.60 | 50 | ★ 3.3 | 82 | BULK-fa55ac0e |
| 21045 | Bulk Product c202f418 | Books | $410.50 | 76 | ★ 2.4 | 28 | BULK-d34c659e |
| 21046 | Bulk Product eeb5a8ee | Toys & Games | $240.93 | 124 | ★ 0.4 | 26 | BULK-479f5e9b |
| 21047 | Bulk Product 91e38a76 | Clothing | $341.60 | 198 | ★ 2.8 | 17 | BULK-35a4643f |
| 21048 | Bulk Product 143e5516 | Sports & Outdoors | $652.42 | 222 | ★ 1.5 | 38 | BULK-7ed292cc |
| 21049 | Bulk Product 29c2e401 | Toys & Games | $804.08 | 160 | ★ 4.3 | 49 | BULK-c1d2821a |
| 21050 | Bulk Product bea6e53a | Electronics | $502.20 | 492 | ★ 2.3 | 76 | BULK-3fdece4b |
| 21051 | Bulk Product 9c5f8aeb | Books | $930.38 | 362 | ★ 4.2 | 72 | BULK-4378f50d |
| 21052 | Bulk Product 49aa7461 | Sports & Outdoors | $390.91 | 142 | ★ 1.3 | 9 | BULK-4ef2169f |
| 21053 | Bulk Product a4aec75c | Sports & Outdoors | $255.68 | 129 | ★ 4.1 | 11 | BULK-afbb320f |
| 21054 | Bulk Product 872894fa | Home & Garden | $409.42 | 412 | ★ 0.5 | 67 | BULK-6b2bd323 |
| 21055 | Bulk Product 83139fab | Toys & Games | $461.00 | 151 | ★ 1.9 | 14 | BULK-7ab28cb5 |
| 21056 | Bulk Product 52b7a9ee | Books | $224.25 | 375 | ★ 0.9 | 43 | BULK-2e5c91b5 |
| 21057 | Bulk Product 511892ed | Sports & Outdoors | $222.23 | 38 | ★ 3.9 | 96 | BULK-03d5025d |
| 21058 | Bulk Product 45031d8c | Electronics | $693.14 | 375 | ★ 3.5 | 4 | BULK-85f30089 |
| 21059 | Bulk Product 2655d29e | Electronics | $24.45 | 36 | ★ 0.4 | 60 | BULK-0c2ea8a7 |
// 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
};
}