Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

32 ms

Page Size

25

Current Page

975 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 975 Results Showing 24351 - 24375 of 24441

ID Name Category Price Stock Rating Reviews SKU
24910 Bulk Product 51e2ac46 Books $881.96 126 2.0 1 BULK-957fa2b1
24911 Bulk Product 1f9e73e9 Sports & Outdoors $143.71 71 4.5 72 BULK-ace92267
24912 Bulk Product 343b81ac Clothing $869.09 395 1.6 20 BULK-6e9ce55a
24913 Bulk Product e9772ab1 Home & Garden $895.95 183 1.8 63 BULK-b0cf5b95
24914 Bulk Product b61abd37 Toys & Games $777.08 108 4.2 30 BULK-03484257
24915 Bulk Product 9b04c751 Electronics $666.46 296 0.1 73 BULK-ee81aca7
24916 Bulk Product 4aad75b1 Electronics $730.07 204 1.8 12 BULK-cd398bac
24917 Bulk Product cab593b0 Home & Garden $277.54 383 1.8 48 BULK-60b06da7
24918 Bulk Product 07aef9fe Toys & Games $715.52 218 1.5 90 BULK-6fe10448
24919 Bulk Product 39e6fed9 Books $263.22 362 2.4 91 BULK-6ad6ca11
24920 Bulk Product 4f25eb1b Books $983.91 31 3.5 8 BULK-d0c53e7e
24921 Bulk Product 41dba946 Home & Garden $250.02 484 3.2 60 BULK-a14bd575
24922 Bulk Product 642410e9 Electronics $474.83 304 1.5 7 BULK-8c3c9b3e
24923 Bulk Product 3f10e254 Electronics $727.41 405 0.5 93 BULK-0530c44f
24924 Bulk Product b0b4b3be Electronics $635.18 119 2.9 15 BULK-ed069fb3
24925 Bulk Product 6b6bdedb Electronics $883.48 320 2.7 23 BULK-41420f7b
24926 Bulk Product 9cf55f28 Home & Garden $582.65 119 4.4 80 BULK-cbc49f6e
24927 Bulk Product ba716b35 Books $604.37 364 1.5 83 BULK-dd48ec89
24928 Bulk Product d32ebf4f Clothing $101.30 461 4.4 21 BULK-077a7c3e
24929 Bulk Product dcdc02eb Electronics $223.06 361 3.9 9 BULK-8af77153
24930 Bulk Product 40fcdbd1 Toys & Games $454.52 277 1.0 29 BULK-5b788614
24931 Bulk Product 7ea612f9 Electronics $932.94 126 4.6 53 BULK-95f5cc91
24932 Bulk Product 69528a08 Sports & Outdoors $266.40 219 1.7 21 BULK-97a5d1de
24933 Bulk Product 8b78197d Sports & Outdoors $122.03 464 3.1 8 BULK-90451479
24934 Bulk Product 085ba039 Toys & Games $870.87 486 2.1 19 BULK-ff6c4b0e
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