Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

14 ms

Page Size

25

Current Page

567 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 567 Results Showing 14151 - 14175 of 24441

ID Name Category Price Stock Rating Reviews SKU
14710 Bulk Product 2a3c2777 Sports & Outdoors $830.84 45 0.4 63 BULK-c546db20
14711 Bulk Product 12977179 Sports & Outdoors $152.29 98 0.5 93 BULK-2014d5f9
14712 Bulk Product 9f0b5d93 Books $844.19 401 1.4 69 BULK-fcec8b51
14713 Bulk Product 8c91dd71 Books $961.74 459 1.8 54 BULK-799a57f8
14714 Bulk Product 7ca6f653 Home & Garden $544.96 280 4.5 71 BULK-2ab00c6e
14715 Bulk Product 42e47ac5 Electronics $127.30 155 1.1 22 BULK-63fd7d87
14716 Bulk Product 2fc3af54 Clothing $605.49 343 0.1 70 BULK-d7894916
14717 Bulk Product 117995ec Home & Garden $146.66 110 2.2 82 BULK-fa56afde
14718 Bulk Product 40a570a9 Clothing $573.07 24 2.1 55 BULK-8e6c4701
14719 Bulk Product d91d5bb2 Home & Garden $186.97 18 0.2 27 BULK-9c5d1e2b
14720 Bulk Product f3324795 Home & Garden $245.76 279 3.7 46 BULK-a19bbdd2
14721 Bulk Product 27ad7cf7 Home & Garden $207.45 313 0.5 49 BULK-35106cd4
14722 Bulk Product 8e7bf0fb Books $734.86 458 2.3 37 BULK-42889131
14723 Bulk Product 6663aabc Home & Garden $468.39 116 1.3 91 BULK-603a415d
14724 Bulk Product a7803412 Books $364.65 335 3.8 22 BULK-c6db263a
14725 Bulk Product 1a14044d Sports & Outdoors $116.41 109 2.1 45 BULK-d0226918
14726 Bulk Product 6233053f Clothing $489.30 372 4.2 12 BULK-63b510d2
14727 Bulk Product a9603b8a Home & Garden $546.71 60 3.4 71 BULK-00fd1bb4
14728 Bulk Product e4b64839 Toys & Games $999.62 7 0.7 72 BULK-dcbc0a61
14729 Bulk Product c2b9e6ed Home & Garden $536.62 271 3.1 20 BULK-1c1f74e7
14730 Bulk Product 43821dab Toys & Games $321.12 71 1.4 34 BULK-8915dfa8
14731 Bulk Product 1b0dd9bb Books $77.99 371 4.9 6 BULK-03f8c839
14732 Bulk Product 3d0fbe4f Sports & Outdoors $100.73 470 3.5 18 BULK-f046333f
14733 Bulk Product bcab2379 Home & Garden $504.30 421 3.3 27 BULK-2b317a86
14734 Bulk Product 5ef87bfc Electronics $508.70 187 4.5 4 BULK-81cb84bf
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