Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

33 ms

Page Size

25

Current Page

129 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 129 Results Showing 3201 - 3225 of 24441

ID Name Category Price Stock Rating Reviews SKU
3596 Mega Office Supplies Product Mini Office Supplies $670.22 356 1.2 919 SKU-003596
3597 Elite Health & Beauty Product Pro Health & Beauty $198.69 32 3.3 375 SKU-003597
3598 Standard Office Supplies Product Mini Office Supplies $317.02 13 4.3 622 SKU-003598
3599 Pro Books Product Lite Books $230.88 20 2.3 958 SKU-003599
3600 Super Office Supplies Product Pro Office Supplies $191.71 448 3.0 515 SKU-003600
3601 Premium Sports & Outdoors Product Advanced Sports & Outdoors $405.55 109 2.0 214 SKU-003601
3602 Premium Automotive Product Mini Automotive $320.01 468 4.4 638 SKU-003602
3603 Super Toys & Games Product Special Edition Toys & Games $272.73 295 3.0 911 SKU-003603
3604 Pro Health & Beauty Product Plus Health & Beauty $337.23 477 1.2 675 SKU-003604
3605 Standard Clothing Product Lite Clothing $978.04 398 1.8 94 SKU-003605
3606 Economy Sports & Outdoors Product Plus Sports & Outdoors $193.88 139 3.9 871 SKU-003606
3607 Premium Home & Garden Product Pro Home & Garden $561.06 313 4.5 422 SKU-003607
3608 Super Home & Garden Product Mini Home & Garden $20.23 276 4.7 498 SKU-003608
3609 Premium Automotive Product Mini Automotive $860.49 258 1.7 690 SKU-003609
3610 Elite Health & Beauty Product Max Health & Beauty $426.21 444 2.9 321 SKU-003610
3611 Elite Office Supplies Product XL Office Supplies $759.27 292 5.0 602 SKU-003611
3612 Elite Books Product Mini Books $588.49 438 1.3 775 SKU-003612
3613 Deluxe Electronics Product Plus Electronics $536.65 448 3.5 843 SKU-003613
3614 Mega Sports & Outdoors Product Special Edition Sports & Outdoors $200.05 374 4.1 25 SKU-003614
3615 Pro Food & Grocery Product 2024 Food & Grocery $69.12 49 1.1 531 SKU-003615
3616 Mega Automotive Product Max Automotive $753.04 463 2.5 967 SKU-003616
3617 Ultra Health & Beauty Product 2024 Health & Beauty $666.98 168 1.3 177 SKU-003617
3618 Standard Clothing Product Plus Clothing $846.89 196 4.1 262 SKU-003618
3619 Deluxe Sports & Outdoors Product Pro Sports & Outdoors $698.23 92 2.0 842 SKU-003619
3620 Professional Sports & Outdoors Product Lite Sports & Outdoors $593.11 180 3.9 611 SKU-003620
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