Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

25 ms

Page Size

25

Current Page

154 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 154 Results Showing 3826 - 3850 of 24441

ID Name Category Price Stock Rating Reviews SKU
4305 Professional Clothing Product Advanced Clothing $194.42 484 3.8 420 SKU-004305
4306 Mega Toys & Games Product Pro Toys & Games $129.89 85 2.4 145 SKU-004306
4307 Mega Health & Beauty Product 2024 Health & Beauty $751.25 5 3.2 663 SKU-004307
4309 Premium Electronics Product XL Electronics $611.20 152 2.9 368 SKU-004309
4310 Mega Toys & Games Product Advanced Toys & Games $73.16 271 4.7 677 SKU-004310
4311 Deluxe Clothing Product Classic Clothing $51.37 271 2.9 699 SKU-004311
4312 Ultra Books Product Plus Books $547.64 79 2.7 621 SKU-004312
4313 Elite Books Product Advanced Books $656.93 346 2.1 367 SKU-004313
4314 Premium Books Product Mini Books $549.05 160 2.6 90 SKU-004314
4315 Elite Toys & Games Product Plus Toys & Games $482.31 381 2.6 267 SKU-004315
4316 Elite Home & Garden Product Special Edition Home & Garden $596.46 300 3.6 839 SKU-004316
4318 Pro Office Supplies Product Max Office Supplies $80.89 407 4.0 885 SKU-004318
4319 Professional Automotive Product Classic Automotive $118.65 213 4.2 187 SKU-004319
4320 Ultra Sports & Outdoors Product Special Edition Sports & Outdoors $68.30 40 1.9 179 SKU-004320
4321 Super Automotive Product Max Automotive $151.85 6 3.3 660 SKU-004321
4322 Economy Toys & Games Product XL Toys & Games $66.12 285 2.6 279 SKU-004322
4323 Elite Clothing Product Advanced Clothing $659.70 399 1.6 789 SKU-004323
4324 Mega Home & Garden Product Pro Home & Garden $640.07 492 1.1 257 SKU-004324
4326 Mega Clothing Product Advanced Clothing $656.85 20 1.1 203 SKU-004326
4327 Elite Food & Grocery Product Special Edition Food & Grocery $848.59 169 1.8 685 SKU-004327
4328 Elite Books Product 2024 Books $545.07 132 3.4 532 SKU-004328
4329 Ultra Books Product Pro Books $179.97 458 1.7 586 SKU-004329
4330 Professional Health & Beauty Product XL Health & Beauty $71.17 41 2.0 657 SKU-004330
4331 Professional Office Supplies Product Classic Office Supplies $448.63 24 4.1 134 SKU-004331
4332 Mega Food & Grocery Product XL Food & Grocery $130.97 117 2.3 437 SKU-004332
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