Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

71 ms

Page Size

25

Current Page

119 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 119 Results Showing 2951 - 2975 of 24441

ID Name Category Price Stock Rating Reviews SKU
3313 Mega Electronics Product Lite Electronics $331.73 285 3.8 561 SKU-003313
3314 Deluxe Food & Grocery Product Plus Food & Grocery $868.60 98 2.2 764 SKU-003314
3315 Standard Automotive Product XL Automotive $360.23 157 3.1 959 SKU-003315
3316 Deluxe Electronics Product Pro Electronics $405.64 219 2.5 358 SKU-003316
3317 Super Toys & Games Product Classic Toys & Games $745.16 413 2.6 186 SKU-003317
3319 Mega Food & Grocery Product Pro Food & Grocery $392.05 481 3.8 62 SKU-003319
3320 Economy Food & Grocery Product Lite Food & Grocery $311.75 49 1.2 132 SKU-003320
3321 Super Automotive Product 2024 Automotive $273.46 254 4.3 701 SKU-003321
3322 Mega Food & Grocery Product XL Food & Grocery $582.83 259 1.5 233 SKU-003322
3323 Deluxe Food & Grocery Product XL Food & Grocery $303.80 116 2.9 817 SKU-003323
3324 Premium Sports & Outdoors Product Advanced Sports & Outdoors $671.18 162 2.1 633 SKU-003324
3325 Pro Electronics Product Special Edition Electronics $337.35 369 1.0 837 SKU-003325
3327 Pro Electronics Product 2024 Electronics $586.67 408 3.4 222 SKU-003327
3328 Deluxe Clothing Product 2024 Clothing $856.07 302 1.4 323 SKU-003328
3329 Professional Office Supplies Product Classic Office Supplies $553.96 205 2.4 115 SKU-003329
3330 Deluxe Books Product Special Edition Books $398.52 270 1.9 655 SKU-003330
3331 Standard Office Supplies Product Mini Office Supplies $917.36 364 3.6 130 SKU-003331
3332 Pro Food & Grocery Product Pro Food & Grocery $240.76 411 4.0 730 SKU-003332
3334 Elite Toys & Games Product Plus Toys & Games $532.47 358 3.6 723 SKU-003334
3335 Premium Office Supplies Product Mini Office Supplies $698.69 445 2.8 760 SKU-003335
3336 Mega Toys & Games Product Pro Toys & Games $169.48 454 3.2 794 SKU-003336
3337 Ultra Automotive Product 2024 Automotive $482.64 476 3.7 284 SKU-003337
3338 Professional Office Supplies Product Special Edition Office Supplies $841.31 3 3.2 850 SKU-003338
3339 Ultra Office Supplies Product 2024 Office Supplies $607.74 423 1.7 416 SKU-003339
3340 Mega Home & Garden Product Mini Home & Garden $451.60 462 1.8 160 SKU-003340
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