Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

32 ms

Page Size

25

Current Page

531 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 531 Results Showing 13251 - 13275 of 24441

ID Name Category Price Stock Rating Reviews SKU
13810 Bulk Product 43dfbae6 Clothing $265.96 250 0.5 11 BULK-64a698fb
13811 Bulk Product 7b590d1b Clothing $284.99 245 0.8 18 BULK-dc8f0e35
13812 Bulk Product 174e5468 Sports & Outdoors $591.16 258 2.0 50 BULK-010ba412
13813 Bulk Product 51902f3e Toys & Games $285.68 389 2.0 88 BULK-0ffa41e5
13814 Bulk Product 853ead85 Electronics $962.05 328 0.2 85 BULK-d462c3c8
13815 Bulk Product 10a4dde7 Home & Garden $682.97 47 0.9 80 BULK-47049041
13816 Bulk Product df07df93 Books $473.32 159 2.7 50 BULK-fe2d2208
13817 Bulk Product b47f7f29 Home & Garden $852.89 354 2.8 25 BULK-9406ebad
13818 Bulk Product 0ee37e47 Electronics $502.40 364 0.7 48 BULK-9f676fe0
13819 Bulk Product 402fbaec Electronics $774.88 338 4.4 31 BULK-141e17de
13820 Bulk Product 7b4181e1 Books $242.40 470 3.6 73 BULK-f1dba0e6
13821 Bulk Product 8bb17a8e Home & Garden $105.08 182 3.6 32 BULK-5cb56a4f
13822 Bulk Product 63115194 Sports & Outdoors $570.64 497 4.5 30 BULK-034bf0d9
13823 Bulk Product 58f17f74 Toys & Games $78.04 366 3.0 49 BULK-94da27ea
13824 Bulk Product b6a763f9 Electronics $341.41 199 3.4 84 BULK-5f520375
13825 Bulk Product a4cfa7fb Toys & Games $412.02 422 3.7 42 BULK-703d6f4b
13826 Bulk Product f9727e14 Clothing $800.60 155 0.0 25 BULK-1914b966
13827 Bulk Product 26dfec28 Home & Garden $799.51 73 1.6 12 BULK-d41dd44c
13828 Bulk Product 9cb6499d Clothing $71.30 454 3.8 64 BULK-8a0cf727
13829 Bulk Product a4b96e4d Books $960.61 195 3.0 31 BULK-bcbdf5f8
13830 Bulk Product 516d071f Books $977.51 155 0.1 61 BULK-ad07e2e3
13831 Bulk Product a4384fa6 Sports & Outdoors $709.33 209 3.2 41 BULK-8f4e6936
13832 Bulk Product c2e1598f Home & Garden $686.79 145 1.3 70 BULK-32a11adf
13833 Bulk Product 1ed1b651 Sports & Outdoors $943.68 321 2.8 99 BULK-70a65841
13834 Bulk Product 8214c1b9 Toys & Games $139.25 53 4.6 56 BULK-4e6c8886
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