Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

8 ms

Page Size

25

Current Page

155 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 155 Results Showing 3851 - 3875 of 24441

ID Name Category Price Stock Rating Reviews SKU
4333 Professional Toys & Games Product 2024 Toys & Games $313.29 236 2.3 617 SKU-004333
4334 Ultra Books Product Plus Books $253.48 363 4.6 561 SKU-004334
4335 Ultra Sports & Outdoors Product Special Edition Sports & Outdoors $462.56 72 3.6 529 SKU-004335
4336 Pro Toys & Games Product Plus Toys & Games $182.73 45 2.9 631 SKU-004336
4337 Economy Food & Grocery Product Advanced Food & Grocery $970.57 21 4.7 365 SKU-004337
4338 Mega Automotive Product Mini Automotive $615.95 376 4.4 110 SKU-004338
4339 Deluxe Food & Grocery Product Lite Food & Grocery $355.82 452 2.5 634 SKU-004339
4340 Elite Books Product Mini Books $165.07 297 3.0 810 SKU-004340
4341 Super Books Product XL Books $360.80 363 4.6 641 SKU-004341
4342 Elite Books Product 2024 Books $895.55 268 4.6 466 SKU-004342
4343 Deluxe Office Supplies Product Max Office Supplies $395.23 346 2.8 256 SKU-004343
4344 Ultra Office Supplies Product 2024 Office Supplies $356.82 20 1.4 771 SKU-004344
4345 Ultra Toys & Games Product XL Toys & Games $463.02 427 4.4 530 SKU-004345
4346 Deluxe Sports & Outdoors Product Advanced Sports & Outdoors $957.61 322 4.5 327 SKU-004346
4347 Deluxe Food & Grocery Product Classic Food & Grocery $303.82 239 4.3 590 SKU-004347
4348 Deluxe Sports & Outdoors Product Special Edition Sports & Outdoors $195.57 36 4.4 718 SKU-004348
4349 Pro Electronics Product Lite Electronics $548.79 112 1.2 444 SKU-004349
4350 Standard Toys & Games Product Plus Toys & Games $831.16 355 3.7 136 SKU-004350
4351 Economy Books Product Mini Books $792.61 336 4.9 996 SKU-004351
4352 Mega Automotive Product Plus Automotive $882.00 285 1.9 88 SKU-004352
4353 Ultra Home & Garden Product Classic Home & Garden $266.18 441 2.1 431 SKU-004353
4354 Professional Sports & Outdoors Product Advanced Sports & Outdoors $122.46 171 3.9 451 SKU-004354
4355 Economy Office Supplies Product Mini Office Supplies $841.89 415 3.0 354 SKU-004355
4356 Super Electronics Product Classic Electronics $993.86 180 4.3 682 SKU-004356
4357 Professional Automotive Product Max Automotive $978.12 435 1.2 688 SKU-004357
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