Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

9 ms

Page Size

25

Current Page

109 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 109 Results Showing 2701 - 2725 of 24441

ID Name Category Price Stock Rating Reviews SKU
3026 Ultra Toys & Games Product 2024 Toys & Games $18.12 220 4.1 758 SKU-003026
3028 Mega Books Product Pro Books $274.83 349 3.6 936 SKU-003028
3029 Elite Food & Grocery Product Classic Food & Grocery $293.32 386 2.1 988 SKU-003029
3030 Elite Books Product Classic Books $957.83 14 4.2 807 SKU-003030
3031 Standard Health & Beauty Product Pro Health & Beauty $763.32 432 4.9 246 SKU-003031
3032 Mega Health & Beauty Product Plus Health & Beauty $201.25 423 4.9 484 SKU-003032
3033 Super Sports & Outdoors Product Plus Sports & Outdoors $860.77 292 4.9 172 SKU-003033
3034 Mega Books Product Max Books $891.73 181 4.5 465 SKU-003034
3035 Ultra Books Product Plus Books $215.94 202 3.1 188 SKU-003035
3036 Premium Health & Beauty Product Special Edition Health & Beauty $106.45 245 2.7 972 SKU-003036
3037 Economy Office Supplies Product Max Office Supplies $267.97 417 3.8 331 SKU-003037
3038 Professional Health & Beauty Product 2024 Health & Beauty $474.09 434 2.1 81 SKU-003038
3039 Elite Office Supplies Product 2024 Office Supplies $881.24 113 2.1 832 SKU-003039
3040 Deluxe Home & Garden Product Special Edition Home & Garden $823.94 110 1.1 594 SKU-003040
3041 Economy Office Supplies Product 2024 Office Supplies $223.57 193 1.1 722 SKU-003041
3042 Pro Home & Garden Product Lite Home & Garden $522.14 127 1.3 687 SKU-003042
3043 Elite Food & Grocery Product Plus Food & Grocery $731.59 71 4.6 256 SKU-003043
3044 Super Automotive Product Classic Automotive $279.29 271 2.8 19 SKU-003044
3045 Economy Sports & Outdoors Product Mini Sports & Outdoors $791.22 163 2.6 434 SKU-003045
3046 Standard Sports & Outdoors Product XL Sports & Outdoors $145.60 387 4.8 673 SKU-003046
3049 Mega Toys & Games Product Special Edition Toys & Games $96.50 487 4.0 894 SKU-003049
3050 Ultra Food & Grocery Product Max Food & Grocery $714.57 275 1.4 568 SKU-003050
3051 Elite Books Product 2024 Books $553.29 308 3.0 299 SKU-003051
3052 Elite Office Supplies Product Plus Office Supplies $213.29 476 4.0 660 SKU-003052
3053 Super Office Supplies Product 2024 Office Supplies $105.70 353 2.8 356 SKU-003053
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