Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

42 ms

Page Size

25

Current Page

213 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 213 Results Showing 5301 - 5325 of 24441

ID Name Category Price Stock Rating Reviews SKU
5860 Bulk Product 330f3a89 Electronics $256.76 330 1.0 57 BULK-11b0713e
5861 Bulk Product accee818 Sports & Outdoors $528.54 40 2.7 99 BULK-6c240704
5862 Bulk Product 2846b2d7 Electronics $16.55 20 3.3 78 BULK-a9c838a6
5863 Bulk Product 1917215a Toys & Games $623.28 430 4.2 13 BULK-e99f8cbb
5864 Bulk Product bb5d1318 Home & Garden $334.86 336 2.2 35 BULK-4e6aaf7b
5865 Bulk Product 571784a5 Sports & Outdoors $81.15 27 3.1 72 BULK-6655be7a
5866 Bulk Product 738787f6 Toys & Games $122.32 475 2.3 16 BULK-b37cfec6
5867 Bulk Product 52274214 Sports & Outdoors $546.91 73 0.5 25 BULK-d3e8e676
5868 Bulk Product 7f9d118d Clothing $573.11 101 4.4 72 BULK-cd485633
5869 Bulk Product 6c201971 Sports & Outdoors $293.89 36 0.3 26 BULK-aa0def41
5870 Bulk Product 79255219 Clothing $174.33 346 0.4 5 BULK-98e778e6
5871 Bulk Product d4921895 Sports & Outdoors $550.39 377 4.4 56 BULK-bfbe77ad
5872 Bulk Product 03e727c2 Books $455.13 381 1.7 76 BULK-6bf5de43
5873 Bulk Product 58417bda Clothing $570.93 400 2.0 90 BULK-8bb65b4e
5874 Bulk Product 53e80fd0 Books $259.28 416 2.6 73 BULK-8ee65b4f
5875 Bulk Product 27fbba83 Home & Garden $612.07 104 4.6 35 BULK-792ae9df
5876 Bulk Product 1fc90760 Clothing $542.53 345 4.8 58 BULK-9081139b
5877 Bulk Product 7414e96c Books $624.46 293 3.6 17 BULK-1d48fe1e
5878 Bulk Product 5d5187f1 Clothing $258.42 368 1.2 9 BULK-3b4ad242
5879 Bulk Product 710bb3ee Books $253.37 140 2.8 72 BULK-16d13eef
5880 Bulk Product fcf002b1 Books $635.65 258 3.6 12 BULK-38a0c2c2
5881 Bulk Product 1d6de4d1 Clothing $601.66 192 1.3 29 BULK-949b52ae
5882 Bulk Product 9f20a69d Books $518.01 76 1.4 98 BULK-f77153e0
5883 Bulk Product 48e99d16 Toys & Games $389.55 438 3.7 0 BULK-b11bdcde
5884 Bulk Product 22a4815e Home & Garden $375.52 236 0.8 19 BULK-960002b6
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