Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

23 ms

Page Size

25

Current Page

144 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 144 Results Showing 3576 - 3600 of 24441

ID Name Category Price Stock Rating Reviews SKU
4014 Pro Books Product Mini Books $273.61 110 2.2 521 SKU-004014
4015 Deluxe Sports & Outdoors Product XL Sports & Outdoors $575.23 476 4.6 174 SKU-004015
4016 Super Clothing Product 2024 Clothing $549.42 209 4.4 529 SKU-004016
4017 Deluxe Health & Beauty Product Advanced Health & Beauty $211.81 347 4.5 243 SKU-004017
4019 Deluxe Books Product Lite Books $505.20 258 4.6 65 SKU-004019
4020 Standard Books Product Pro Books $13.80 180 4.6 489 SKU-004020
4022 Elite Health & Beauty Product Pro Health & Beauty $164.78 92 1.7 736 SKU-004022
4023 Pro Food & Grocery Product Advanced Food & Grocery $198.16 31 2.0 355 SKU-004023
4026 Premium Sports & Outdoors Product Lite Sports & Outdoors $730.41 106 1.4 19 SKU-004026
4027 Elite Health & Beauty Product Classic Health & Beauty $451.00 290 2.9 566 SKU-004027
4028 Professional Sports & Outdoors Product Classic Sports & Outdoors $697.85 460 1.0 797 SKU-004028
4029 Deluxe Electronics Product Advanced Electronics $710.43 373 2.1 383 SKU-004029
4030 Ultra Electronics Product Special Edition Electronics $386.72 197 4.8 242 SKU-004030
4031 Super Sports & Outdoors Product Max Sports & Outdoors $910.48 135 3.8 75 SKU-004031
4032 Mega Office Supplies Product XL Office Supplies $275.23 442 2.9 871 SKU-004032
4033 Professional Office Supplies Product Pro Office Supplies $537.70 470 2.9 492 SKU-004033
4035 Deluxe Clothing Product Classic Clothing $849.42 111 1.2 991 SKU-004035
4036 Standard Automotive Product Advanced Automotive $361.22 77 3.2 140 SKU-004036
4037 Premium Toys & Games Product Special Edition Toys & Games $794.69 152 1.8 349 SKU-004037
4038 Elite Toys & Games Product Mini Toys & Games $697.75 23 1.5 107 SKU-004038
4040 Super Sports & Outdoors Product Special Edition Sports & Outdoors $916.79 226 2.4 731 SKU-004040
4042 Deluxe Office Supplies Product Pro Office Supplies $963.86 211 4.2 541 SKU-004042
4043 Super Sports & Outdoors Product XL Sports & Outdoors $589.65 427 1.7 369 SKU-004043
4045 Deluxe Office Supplies Product Advanced Office Supplies $472.85 211 2.0 425 SKU-004045
4046 Elite Clothing Product Pro Clothing $428.98 41 3.1 908 SKU-004046
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