Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

24 ms

Page Size

25

Current Page

495 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 495 Results Showing 12351 - 12375 of 24441

ID Name Category Price Stock Rating Reviews SKU
12910 Bulk Product 19d73b7d Books $184.45 256 3.3 98 BULK-61bd8e9e
12911 Bulk Product 5fbaed30 Clothing $740.17 366 2.2 12 BULK-26c11ba8
12912 Bulk Product 86898a07 Home & Garden $874.76 36 3.8 81 BULK-221a15b9
12913 Bulk Product 71ec8631 Toys & Games $346.53 499 1.4 38 BULK-091ee728
12914 Bulk Product f528d9ed Electronics $907.19 180 4.1 51 BULK-9ed91cfc
12915 Bulk Product 74e17ac7 Electronics $455.75 108 0.3 28 BULK-b6c43538
12916 Bulk Product 06ad61cf Clothing $492.53 189 3.4 63 BULK-95e66561
12917 Bulk Product 90f9b432 Books $971.35 218 2.3 8 BULK-be7c7fa6
12918 Bulk Product f883d3fd Clothing $930.89 159 3.3 6 BULK-f42b90f6
12919 Bulk Product dec39d3d Clothing $220.52 331 1.0 54 BULK-c65ed877
12920 Bulk Product 2171b0cc Sports & Outdoors $150.10 237 1.0 82 BULK-6d7ab3f7
12921 Bulk Product 08b82a74 Toys & Games $302.43 209 4.7 85 BULK-8b407736
12922 Bulk Product fcb5f1d1 Books $141.21 439 4.8 74 BULK-986b4295
12923 Bulk Product dc115f1a Sports & Outdoors $620.35 156 3.5 24 BULK-effd8413
12924 Bulk Product b3031f1d Home & Garden $364.67 402 2.0 53 BULK-459399a5
12925 Bulk Product 533c363b Electronics $177.07 274 2.8 57 BULK-4f489af4
12926 Bulk Product 294309bc Clothing $65.40 176 3.7 24 BULK-e3932022
12927 Bulk Product 7f4144d0 Toys & Games $536.01 238 2.8 92 BULK-916e280a
12928 Bulk Product 2ff6c59f Electronics $728.10 252 3.8 83 BULK-4497457f
12929 Bulk Product 5a0542eb Home & Garden $778.46 488 0.2 48 BULK-10d4f3a2
12930 Bulk Product 2f86d1a7 Books $135.15 451 1.1 44 BULK-e61800b4
12931 Bulk Product bd82d4a3 Sports & Outdoors $459.71 437 1.2 15 BULK-7302b039
12932 Bulk Product 9e5159b3 Clothing $871.60 492 1.6 13 BULK-4824fb64
12933 Bulk Product d177a4cc Books $19.96 478 3.8 22 BULK-f991bf38
12934 Bulk Product 694bdf6a Electronics $981.11 207 2.8 24 BULK-3dfb0fc0
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