Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

16 ms

Page Size

25

Current Page

930 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 930 Results Showing 23226 - 23250 of 24441

ID Name Category Price Stock Rating Reviews SKU
23785 Bulk Product 21fe1f71 Home & Garden $174.14 490 0.6 70 BULK-c3632d55
23786 Bulk Product ec34dcf8 Books $914.42 269 0.2 29 BULK-9e2e00e4
23787 Bulk Product 89510708 Books $354.50 332 4.4 91 BULK-478713e9
23788 Bulk Product de42ecbe Books $752.99 488 3.0 6 BULK-0f08501d
23789 Bulk Product 54f130bc Books $758.34 219 3.0 32 BULK-ef13c13d
23790 Bulk Product ac5a4c1b Toys & Games $39.99 9 4.6 7 BULK-9c3775b6
23791 Bulk Product dac08877 Electronics $859.54 462 1.1 17 BULK-80556b3c
23792 Bulk Product a8766d46 Books $650.74 29 2.8 45 BULK-0fe96c0e
23793 Bulk Product 6d4f75c2 Clothing $976.10 295 2.8 54 BULK-8473243f
23794 Bulk Product 5a0d705d Sports & Outdoors $471.44 251 1.8 99 BULK-66f370d1
23795 Bulk Product 7b1030e5 Books $71.14 95 2.0 30 BULK-e524a14b
23796 Bulk Product 0ce1b82e Clothing $254.34 478 4.2 40 BULK-aa2af988
23797 Bulk Product f9441bdc Home & Garden $612.42 215 4.4 17 BULK-8ddcc906
23798 Bulk Product 4b885acd Home & Garden $828.75 411 2.4 65 BULK-fa28941e
23799 Bulk Product 43575b4a Electronics $244.84 63 0.8 10 BULK-0e43de77
23800 Bulk Product ddaccd82 Sports & Outdoors $990.40 301 3.7 21 BULK-6072aa9d
23801 Bulk Product 3b8c23ac Toys & Games $294.53 257 3.6 99 BULK-b61946e5
23802 Bulk Product 2de65ad9 Toys & Games $665.24 383 1.8 63 BULK-e4d3bca8
23803 Bulk Product 837dfe71 Toys & Games $542.13 336 1.4 67 BULK-964088d9
23804 Bulk Product 32c4968e Toys & Games $674.82 238 2.7 45 BULK-478bf5b3
23805 Bulk Product 5f3d3c3e Home & Garden $733.16 424 0.9 77 BULK-d1d66f70
23806 Bulk Product 422ac0f0 Electronics $501.07 425 3.5 27 BULK-70514a42
23807 Bulk Product b9c1cb65 Toys & Games $230.74 237 2.0 44 BULK-a7a4ec2f
23808 Bulk Product 6934b3d9 Sports & Outdoors $199.69 14 4.6 10 BULK-5ebaa77a
23809 Bulk Product 472fc2dc Home & Garden $45.31 138 3.3 40 BULK-4e610665
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