Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

26 ms

Page Size

25

Current Page

160 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 160 Results Showing 3976 - 4000 of 24441

ID Name Category Price Stock Rating Reviews SKU
4479 Economy Office Supplies Product Lite Office Supplies $229.36 205 1.8 437 SKU-004479
4480 Ultra Sports & Outdoors Product Special Edition Sports & Outdoors $137.23 465 4.1 665 SKU-004480
4481 Super Office Supplies Product Max Office Supplies $873.99 59 2.4 572 SKU-004481
4482 Ultra Home & Garden Product Special Edition Home & Garden $678.50 346 3.7 820 SKU-004482
4483 Standard Home & Garden Product Mini Home & Garden $864.44 224 1.6 161 SKU-004483
4485 Premium Electronics Product Special Edition Electronics $509.07 263 1.2 727 SKU-004485
4486 Deluxe Books Product 2024 Books $194.97 497 3.8 996 SKU-004486
4487 Super Automotive Product Mini Automotive $57.26 494 2.1 316 SKU-004487
4488 Deluxe Automotive Product Mini Automotive $191.47 489 3.8 913 SKU-004488
4489 Deluxe Health & Beauty Product Pro Health & Beauty $144.37 273 2.5 126 SKU-004489
4490 Ultra Office Supplies Product Plus Office Supplies $109.68 85 3.4 755 SKU-004490
4491 Ultra Clothing Product Max Clothing $975.26 177 2.5 172 SKU-004491
4492 Ultra Electronics Product Plus Electronics $411.13 103 1.9 266 SKU-004492
4493 Deluxe Electronics Product Lite Electronics $134.55 99 4.6 83 SKU-004493
4494 Super Books Product Advanced Books $552.13 274 1.9 298 SKU-004494
4495 Standard Automotive Product Classic Automotive $70.81 1 1.5 883 SKU-004495
4496 Premium Toys & Games Product Pro Toys & Games $961.19 121 3.5 756 SKU-004496
4497 Premium Sports & Outdoors Product Pro Sports & Outdoors $79.89 182 4.2 385 SKU-004497
4498 Deluxe Sports & Outdoors Product 2024 Sports & Outdoors $88.07 389 2.7 306 SKU-004498
4499 Elite Clothing Product XL Clothing $751.87 471 4.1 508 SKU-004499
4500 Professional Clothing Product Plus Clothing $353.06 363 3.1 566 SKU-004500
4501 Ultra Food & Grocery Product Plus Food & Grocery $451.54 406 4.9 891 SKU-004501
4503 Deluxe Sports & Outdoors Product Max Sports & Outdoors $428.66 378 2.8 706 SKU-004503
4504 Professional Office Supplies Product Mini Office Supplies $634.73 266 3.9 223 SKU-004504
4505 Super Electronics Product Advanced Electronics $981.49 327 3.6 640 SKU-004505
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