Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

11 ms

Page Size

25

Current Page

39 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 39 Results Showing 951 - 975 of 24441

ID Name Category Price Stock Rating Reviews SKU
1069 Ultra Sports & Outdoors Product Plus Sports & Outdoors $68.75 418 4.2 927 SKU-001069
1070 Premium Health & Beauty Product Special Edition Health & Beauty $688.48 183 2.4 253 SKU-001070
1071 Professional Automotive Product Advanced Automotive $352.53 391 1.3 867 SKU-001071
1072 Elite Health & Beauty Product Classic Health & Beauty $114.98 290 3.3 699 SKU-001072
1074 Deluxe Food & Grocery Product Special Edition Food & Grocery $740.81 432 1.8 791 SKU-001074
1075 Standard Books Product 2024 Books $562.61 329 1.6 984 SKU-001075
1076 Premium Office Supplies Product Classic Office Supplies $436.97 63 5.0 140 SKU-001076
1077 Elite Books Product Lite Books $694.75 427 4.5 418 SKU-001077
1078 Economy Automotive Product Lite Automotive $55.89 447 2.1 514 SKU-001078
1079 Standard Automotive Product Mini Automotive $604.53 232 1.9 864 SKU-001079
1080 Premium Office Supplies Product Lite Office Supplies $585.01 314 3.9 79 SKU-001080
1081 Premium Office Supplies Product Lite Office Supplies $389.72 280 3.2 786 SKU-001081
1082 Super Office Supplies Product 2024 Office Supplies $567.39 379 3.1 406 SKU-001082
1083 Standard Clothing Product Special Edition Clothing $388.21 175 1.4 135 SKU-001083
1084 Economy Clothing Product Special Edition Clothing $772.68 398 1.2 224 SKU-001084
1085 Mega Health & Beauty Product Special Edition Health & Beauty $741.15 458 3.6 386 SKU-001085
1086 Deluxe Clothing Product XL Clothing $962.66 133 1.2 679 SKU-001086
1087 Ultra Books Product Max Books $522.00 353 4.0 468 SKU-001087
1088 Pro Sports & Outdoors Product XL Sports & Outdoors $346.24 158 1.0 524 SKU-001088
1089 Standard Automotive Product Pro Automotive $536.27 168 2.4 899 SKU-001089
1090 Elite Electronics Product Lite Electronics $454.77 109 4.3 416 SKU-001090
1091 Ultra Automotive Product 2024 Automotive $973.19 78 4.2 246 SKU-001091
1092 Pro Electronics Product Plus Electronics $949.74 250 3.3 901 SKU-001092
1094 Pro Food & Grocery Product XL Food & Grocery $236.50 49 3.0 214 SKU-001094
1096 Super Toys & Games Product Plus Toys & Games $485.24 251 1.1 906 SKU-001096
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