Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

71 ms

Page Size

25

Current Page

910 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 910 Results Showing 22726 - 22750 of 24441

ID Name Category Price Stock Rating Reviews SKU
23285 Bulk Product a6576c8b Toys & Games $327.21 11 4.4 8 BULK-d1883006
23286 Bulk Product 48893234 Books $236.64 153 2.8 21 BULK-af340445
23287 Bulk Product a83fb0fc Sports & Outdoors $576.21 282 2.9 59 BULK-ecc4a9d4
23288 Bulk Product a83821a9 Toys & Games $239.24 167 3.7 13 BULK-e56f06d7
23289 Bulk Product 3e9b895b Books $110.10 317 1.6 95 BULK-f49d5a9f
23290 Bulk Product c5c68a80 Home & Garden $353.39 482 3.6 47 BULK-3dca51d6
23291 Bulk Product 659d9c29 Books $208.16 202 1.0 9 BULK-09f8a687
23292 Bulk Product 132cf8dd Sports & Outdoors $34.66 13 1.8 44 BULK-47126e9e
23293 Bulk Product 564d5dc6 Clothing $411.29 411 2.0 48 BULK-d7cc543a
23294 Bulk Product 9cd67804 Sports & Outdoors $807.70 258 1.8 36 BULK-2d06c588
23295 Bulk Product 1e609da8 Clothing $265.41 308 3.6 62 BULK-523a2352
23296 Bulk Product b598a4ae Electronics $477.67 8 4.7 46 BULK-a76449ba
23297 Bulk Product d0a5a082 Toys & Games $113.16 310 4.1 28 BULK-8cc2f44a
23298 Bulk Product b125ebfe Toys & Games $566.12 346 2.4 64 BULK-52e1d3f6
23299 Bulk Product 87343733 Home & Garden $919.25 102 3.9 5 BULK-17570821
23300 Bulk Product 93efb1da Sports & Outdoors $21.61 18 3.4 43 BULK-5b0cac5a
23301 Bulk Product ef939f99 Clothing $562.84 432 0.7 25 BULK-78ef8284
23302 Bulk Product b80801ca Books $595.84 149 4.7 28 BULK-a012e79b
23303 Bulk Product 74e64d83 Toys & Games $613.29 147 0.6 60 BULK-51db5730
23304 Bulk Product f5f98c23 Sports & Outdoors $146.58 292 2.0 74 BULK-142ecc2b
23305 Bulk Product ba8a45e5 Electronics $629.74 388 1.2 78 BULK-832cab01
23306 Bulk Product 808e5c4e Electronics $933.35 122 4.4 32 BULK-8a74a8bf
23307 Bulk Product 9f940512 Books $133.23 140 3.0 2 BULK-05cff44a
23308 Bulk Product 913f5a6a Clothing $599.65 291 4.8 4 BULK-a4ecfcf7
23309 Bulk Product 7373085b Sports & Outdoors $141.75 492 1.9 69 BULK-f1e6f170
Implementation Code
// 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
    };
}
Pagination Best Practices
  • Always use OrderBy: Skip/Take require stable sorting for consistent results
  • Use AsNoTracking(): Pagination queries are typically read-only
  • Consider caching: Cache total count if dataset changes infrequently
  • Limit max page size: Prevent users from requesting too many records at once
  • Use indexed columns: Ensure ORDER BY columns are indexed for performance