Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 8060 | Bulk Product ba89a3bc | Electronics | $188.95 | 136 | ★ 4.8 | 34 | BULK-cc9cd517 |
| 8061 | Bulk Product d65f30bf | Toys & Games | $874.04 | 392 | ★ 2.4 | 48 | BULK-73be2f2e |
| 8062 | Bulk Product 244e6835 | Clothing | $927.50 | 210 | ★ 2.8 | 24 | BULK-7f6a272a |
| 8063 | Bulk Product db39f1be | Sports & Outdoors | $170.24 | 173 | ★ 0.3 | 27 | BULK-0040c701 |
| 8064 | Bulk Product 3fe542a6 | Books | $104.80 | 199 | ★ 3.2 | 93 | BULK-6ee40e06 |
| 8065 | Bulk Product b650a73e | Electronics | $74.11 | 262 | ★ 4.1 | 23 | BULK-7aa5c2d5 |
| 8066 | Bulk Product fef7824c | Sports & Outdoors | $763.73 | 292 | ★ 0.3 | 12 | BULK-e97d5f7a |
| 8067 | Bulk Product b17fcbd9 | Clothing | $960.96 | 249 | ★ 1.6 | 96 | BULK-bd306b75 |
| 8068 | Bulk Product 315adb1b | Toys & Games | $892.06 | 235 | ★ 3.7 | 97 | BULK-ef9bdcc0 |
| 8069 | Bulk Product afe3d67a | Books | $991.74 | 346 | ★ 4.8 | 41 | BULK-1c2939f5 |
| 8070 | Bulk Product 732b62b8 | Books | $577.04 | 308 | ★ 4.2 | 40 | BULK-a8d91822 |
| 8071 | Bulk Product d8800778 | Clothing | $336.48 | 130 | ★ 4.5 | 5 | BULK-6e338a47 |
| 8072 | Bulk Product 0e2696e9 | Home & Garden | $303.94 | 464 | ★ 1.2 | 49 | BULK-511cc4a7 |
| 8073 | Bulk Product 0e7eb122 | Electronics | $933.12 | 271 | ★ 2.4 | 2 | BULK-58258cb8 |
| 8074 | Bulk Product f92db4dc | Electronics | $888.59 | 32 | ★ 4.2 | 4 | BULK-2c587bf8 |
| 8075 | Bulk Product f81f648a | Books | $840.69 | 155 | ★ 5.0 | 34 | BULK-5866e0cd |
| 8076 | Bulk Product 5377ac33 | Clothing | $465.26 | 431 | ★ 1.5 | 46 | BULK-5c32d479 |
| 8077 | Bulk Product cfef9a16 | Home & Garden | $80.79 | 333 | ★ 3.3 | 81 | BULK-e1968554 |
| 8078 | Bulk Product 04909a15 | Sports & Outdoors | $306.09 | 408 | ★ 4.6 | 72 | BULK-10655129 |
| 8079 | Bulk Product e5df4a9f | Books | $659.09 | 345 | ★ 4.3 | 95 | BULK-f995e68d |
| 8080 | Bulk Product f29168a5 | Sports & Outdoors | $891.80 | 88 | ★ 3.2 | 36 | BULK-1c5861f2 |
| 8081 | Bulk Product e5a2c634 | Sports & Outdoors | $59.13 | 448 | ★ 2.0 | 36 | BULK-58a4c401 |
| 8082 | Bulk Product 64236c98 | Sports & Outdoors | $56.81 | 450 | ★ 4.9 | 30 | BULK-99d85049 |
| 8083 | Bulk Product ecafef68 | Books | $149.72 | 309 | ★ 0.7 | 63 | BULK-5d10b8e3 |
| 8084 | Bulk Product 091f1167 | Sports & Outdoors | $674.59 | 468 | ★ 4.3 | 53 | BULK-b30a2190 |
| 8085 | Bulk Product 23fc41f0 | Electronics | $907.01 | 79 | ★ 0.3 | 69 | BULK-35430d6d |
| 8086 | Bulk Product e78f1acd | Books | $919.88 | 260 | ★ 4.1 | 10 | BULK-74e0fa4a |
| 8087 | Bulk Product 42a78f05 | Books | $287.54 | 373 | ★ 2.0 | 47 | BULK-27d1a30f |
| 8088 | Bulk Product 98f6e57c | Clothing | $822.78 | 221 | ★ 2.2 | 94 | BULK-4aa26ed3 |
| 8089 | Bulk Product e8dd3459 | Sports & Outdoors | $34.74 | 255 | ★ 5.0 | 54 | BULK-d528e22a |
| 8090 | Bulk Product d5d04812 | Electronics | $642.36 | 66 | ★ 1.2 | 7 | BULK-c3e1fcea |
| 8091 | Bulk Product a5b0462b | Toys & Games | $713.61 | 299 | ★ 4.2 | 79 | BULK-f5d79d93 |
| 8092 | Bulk Product ef8a7a9d | Clothing | $331.30 | 441 | ★ 4.4 | 44 | BULK-532731e2 |
| 8093 | Bulk Product db049548 | Home & Garden | $815.46 | 69 | ★ 3.8 | 78 | BULK-b33f5608 |
| 8094 | Bulk Product bd8425a9 | Books | $304.63 | 496 | ★ 3.2 | 17 | BULK-6d7fae5f |
| 8095 | Bulk Product f771a766 | Sports & Outdoors | $1,005.42 | 238 | ★ 4.3 | 95 | BULK-66847d2c |
| 8096 | Bulk Product a5bbe5c8 | Home & Garden | $963.79 | 142 | ★ 4.3 | 23 | BULK-e5efddad |
| 8097 | Bulk Product f461ec4c | Electronics | $744.56 | 134 | ★ 3.3 | 61 | BULK-d25d7f97 |
| 8098 | Bulk Product b6165521 | Sports & Outdoors | $521.93 | 49 | ★ 2.5 | 16 | BULK-08b78fa0 |
| 8099 | Bulk Product 3fcf29b2 | Home & Garden | $571.97 | 158 | ★ 2.5 | 13 | BULK-5a401e66 |
| 8100 | Bulk Product 79a99437 | Home & Garden | $662.42 | 315 | ★ 2.4 | 63 | BULK-88bde65d |
| 8101 | Bulk Product 55a29183 | Books | $966.04 | 21 | ★ 0.8 | 62 | BULK-24b54ec7 |
| 8102 | Bulk Product dc40c484 | Clothing | $995.26 | 295 | ★ 0.3 | 63 | BULK-73d3a3eb |
| 8103 | Bulk Product 9e631e40 | Clothing | $210.49 | 317 | ★ 3.1 | 78 | BULK-5a0c4515 |
| 8104 | Bulk Product c7590963 | Home & Garden | $343.76 | 0 | ★ 1.9 | 35 | BULK-123f7e43 |
| 8105 | Bulk Product e8f2d291 | Home & Garden | $305.21 | 220 | ★ 0.9 | 93 | BULK-91f44bf6 |
| 8106 | Bulk Product 5f28f69a | Clothing | $968.48 | 349 | ★ 0.9 | 56 | BULK-fcf734eb |
| 8107 | Bulk Product 8e0d524b | Clothing | $275.36 | 452 | ★ 3.9 | 72 | BULK-cf7c3312 |
| 8108 | Bulk Product b9f85bb5 | Home & Garden | $994.06 | 425 | ★ 2.6 | 80 | BULK-d792ee42 |
| 8109 | Bulk Product b8c1c10b | Sports & Outdoors | $379.99 | 441 | ★ 1.9 | 69 | BULK-4978ac8c |
// 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
};
}