Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

30 ms

Page Size

25

Current Page

781 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 781 Results Showing 19501 - 19525 of 24441

ID Name Category Price Stock Rating Reviews SKU
20060 Bulk Product e045f640 Sports & Outdoors $532.38 407 2.5 71 BULK-23b65c5f
20061 Bulk Product 456e76f8 Home & Garden $93.32 297 3.6 1 BULK-5859a54b
20062 Bulk Product faa199ae Clothing $553.51 44 2.4 12 BULK-38e94265
20063 Bulk Product 1d1ac791 Home & Garden $257.46 259 1.3 32 BULK-f719e17f
20064 Bulk Product bbaa3df9 Home & Garden $815.12 186 0.9 51 BULK-49f19aaf
20065 Bulk Product b9a80743 Toys & Games $450.66 182 2.9 1 BULK-897362fd
20066 Bulk Product b0b17954 Electronics $616.24 420 2.2 55 BULK-68fa97ae
20067 Bulk Product 6fd5606d Electronics $538.95 213 3.4 93 BULK-59762528
20068 Bulk Product abea1d19 Sports & Outdoors $239.53 29 0.8 69 BULK-539234fd
20069 Bulk Product bf1b2f00 Books $603.26 165 3.2 28 BULK-b8d680b5
20070 Bulk Product 27e162d2 Electronics $717.17 261 1.9 45 BULK-5f421634
20071 Bulk Product ac33b4ae Home & Garden $147.76 251 1.5 94 BULK-e8d9046b
20072 Bulk Product f441a030 Clothing $226.40 59 4.4 50 BULK-a53ce563
20073 Bulk Product 36cc96cd Sports & Outdoors $697.43 158 0.5 92 BULK-1d198957
20074 Bulk Product 7e379d77 Toys & Games $125.90 386 0.7 44 BULK-7738d050
20075 Bulk Product cf8fe499 Clothing $80.91 120 0.2 56 BULK-40747199
20076 Bulk Product 1ba06daf Toys & Games $765.73 401 2.5 32 BULK-96ffa06b
20077 Bulk Product d712fb97 Toys & Games $637.46 291 1.3 39 BULK-796a0c48
20078 Bulk Product a8f9f904 Electronics $706.14 92 1.6 61 BULK-7a06667a
20079 Bulk Product b2f83a1b Home & Garden $900.09 308 4.0 13 BULK-6e603b50
20080 Bulk Product 5ab2e380 Clothing $991.55 495 1.4 95 BULK-3477f68e
20081 Bulk Product 03aa063e Books $209.58 489 0.3 59 BULK-3594c67b
20082 Bulk Product 06a591d7 Home & Garden $984.39 112 1.6 95 BULK-6b35fcce
20083 Bulk Product 82813f30 Books $482.17 19 1.9 77 BULK-0a97c018
20084 Bulk Product 5f89092b Clothing $650.33 190 1.7 82 BULK-3054f74a
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