Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

149 ms

Page Size

25

Current Page

912 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 912 Results Showing 22776 - 22800 of 24441

ID Name Category Price Stock Rating Reviews SKU
23335 Bulk Product ccfe2799 Electronics $462.53 98 2.5 88 BULK-e8d28e42
23336 Bulk Product c2263cc5 Home & Garden $723.77 95 0.0 71 BULK-f3df01e0
23337 Bulk Product 8d278846 Electronics $783.69 329 4.3 81 BULK-42495575
23338 Bulk Product 14b44544 Electronics $652.72 327 5.0 82 BULK-92393a59
23339 Bulk Product 74aaded9 Home & Garden $873.05 109 0.9 30 BULK-018642f1
23340 Bulk Product 7e1b15ab Books $175.16 146 1.7 19 BULK-4d3275cd
23341 Bulk Product 250917b5 Clothing $449.41 246 4.9 22 BULK-3a4a51ba
23342 Bulk Product c381fdc5 Toys & Games $906.72 99 4.0 62 BULK-617a6abc
23343 Bulk Product 17f8b1fa Clothing $737.16 394 1.4 86 BULK-48846f95
23344 Bulk Product 8de9e54c Sports & Outdoors $841.93 90 0.9 64 BULK-24cbccb4
23345 Bulk Product 3bbebcda Toys & Games $181.00 57 4.1 31 BULK-b7922fff
23346 Bulk Product 66b07306 Sports & Outdoors $597.33 277 2.8 14 BULK-6bdd92d0
23347 Bulk Product a768de8a Sports & Outdoors $706.38 121 1.2 10 BULK-171df639
23348 Bulk Product 47e0d3c0 Electronics $694.58 92 1.1 76 BULK-971b6015
23349 Bulk Product 069d454c Toys & Games $540.81 227 3.9 14 BULK-84ab76e9
23350 Bulk Product 44e847cc Electronics $17.83 334 0.9 43 BULK-13631919
23351 Bulk Product a87b960e Electronics $714.64 426 4.2 59 BULK-bbde480b
23352 Bulk Product 2e25b2a8 Home & Garden $392.57 253 3.1 70 BULK-03782c3e
23353 Bulk Product 73f3c9d9 Toys & Games $91.87 370 3.5 65 BULK-c7f3c4df
23354 Bulk Product 0e1beba4 Home & Garden $382.42 362 1.4 12 BULK-a8fd3ff1
23355 Bulk Product afcd441c Electronics $471.24 79 3.5 42 BULK-c10607e2
23356 Bulk Product 83ddf114 Sports & Outdoors $943.08 211 4.3 7 BULK-1d97b894
23357 Bulk Product 4e90d07a Sports & Outdoors $839.85 287 2.2 22 BULK-3a9e8b35
23358 Bulk Product 2add3669 Electronics $761.37 351 2.3 50 BULK-8a25f9a3
23359 Bulk Product d610f2cb Books $177.68 6 1.1 58 BULK-8302bd75
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