Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

31 ms

Page Size

25

Current Page

173 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 173 Results Showing 4301 - 4325 of 24441

ID Name Category Price Stock Rating Reviews SKU
4845 Elite Food & Grocery Product Advanced Food & Grocery $78.11 194 3.6 40 SKU-004845
4846 Ultra Automotive Product 2024 Automotive $876.70 113 3.5 44 SKU-004846
4848 Deluxe Sports & Outdoors Product Max Sports & Outdoors $705.02 249 4.5 41 SKU-004848
4849 Standard Automotive Product Classic Automotive $957.93 213 3.1 58 SKU-004849
4850 Standard Food & Grocery Product Pro Food & Grocery $978.93 417 3.7 278 SKU-004850
4851 Economy Automotive Product Lite Automotive $914.25 352 3.7 408 SKU-004851
4852 Super Sports & Outdoors Product Mini Sports & Outdoors $354.58 192 2.9 399 SKU-004852
4853 Super Food & Grocery Product Pro Food & Grocery $307.37 202 2.1 309 SKU-004853
4854 Ultra Electronics Product Plus Electronics $220.76 4 2.2 697 SKU-004854
4855 Elite Sports & Outdoors Product Special Edition Sports & Outdoors $590.68 73 4.2 694 SKU-004855
4856 Pro Electronics Product XL Electronics $986.76 200 1.8 619 SKU-004856
4858 Standard Home & Garden Product Lite Home & Garden $716.29 79 4.4 414 SKU-004858
4859 Standard Food & Grocery Product Advanced Food & Grocery $939.72 384 1.9 570 SKU-004859
4860 Ultra Sports & Outdoors Product 2024 Sports & Outdoors $553.71 104 4.0 750 SKU-004860
4861 Mega Health & Beauty Product Pro Health & Beauty $448.36 169 2.4 360 SKU-004861
4863 Ultra Electronics Product Max Electronics $630.06 184 4.3 365 SKU-004863
4864 Economy Clothing Product 2024 Clothing $980.86 296 3.6 454 SKU-004864
4865 Economy Electronics Product Mini Electronics $37.26 70 3.7 24 SKU-004865
4866 Ultra Electronics Product Advanced Electronics $562.90 441 3.2 889 SKU-004866
4868 Elite Health & Beauty Product Plus Health & Beauty $899.08 397 1.6 817 SKU-004868
4869 Premium Clothing Product Special Edition Clothing $157.33 53 3.9 186 SKU-004869
4870 Premium Books Product Advanced Books $286.91 106 2.6 976 SKU-004870
4871 Premium Clothing Product Plus Clothing $184.62 406 4.5 2 SKU-004871
4872 Economy Toys & Games Product Pro Toys & Games $489.28 279 1.2 383 SKU-004872
4873 Ultra Electronics Product XL Electronics $234.60 164 4.1 871 SKU-004873
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