Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

38 ms

Page Size

25

Current Page

889 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 889 Results Showing 22201 - 22225 of 24441

ID Name Category Price Stock Rating Reviews SKU
22760 Bulk Product ac33c255 Books $754.40 368 3.0 37 BULK-8c069807
22761 Bulk Product 5e6af62b Electronics $626.43 181 4.7 2 BULK-9e0c82db
22762 Bulk Product de492824 Home & Garden $751.37 205 3.0 79 BULK-16a2b4d3
22763 Bulk Product 2c9d6b87 Books $655.79 305 2.4 69 BULK-095d0137
22764 Bulk Product f8dd8995 Toys & Games $893.24 298 0.1 60 BULK-c0c073be
22765 Bulk Product 07faf390 Toys & Games $57.64 215 4.7 79 BULK-5142ff87
22766 Bulk Product 89d13df3 Electronics $668.24 119 2.5 81 BULK-5801599e
22767 Bulk Product ef1fccc3 Clothing $887.94 461 0.3 36 BULK-2ae360a4
22768 Bulk Product bda14bcd Clothing $569.04 84 3.3 90 BULK-2ab458c6
22769 Bulk Product 5c987145 Toys & Games $616.03 138 4.7 17 BULK-52b1917d
22770 Bulk Product 7c74840b Toys & Games $579.53 434 1.0 34 BULK-00da8ac7
22771 Bulk Product f3f157b6 Toys & Games $420.91 307 4.9 48 BULK-79dd97b7
22772 Bulk Product e8e6c521 Clothing $578.87 142 0.6 1 BULK-1b85f0de
22773 Bulk Product d0fda2fe Toys & Games $355.00 107 1.4 68 BULK-072ed0dc
22774 Bulk Product 8cec4feb Toys & Games $299.69 111 2.1 78 BULK-6c3b2213
22775 Bulk Product 1c08e803 Sports & Outdoors $781.83 420 3.1 73 BULK-42d2cc60
22776 Bulk Product f72b3399 Clothing $838.98 165 2.1 77 BULK-ceb8c16e
22777 Bulk Product d12ab782 Clothing $308.21 432 1.2 78 BULK-5f8ccdec
22778 Bulk Product c9fc9844 Sports & Outdoors $755.37 82 0.7 11 BULK-451f15c2
22779 Bulk Product b0140aab Sports & Outdoors $936.44 377 3.9 9 BULK-08e8ec79
22780 Bulk Product 6c12eb29 Sports & Outdoors $447.04 37 3.8 67 BULK-31a5e10b
22781 Bulk Product ae6646db Clothing $626.06 95 0.8 95 BULK-bdf3fa0d
22782 Bulk Product 2450badd Books $779.10 280 0.5 17 BULK-af45f6a3
22783 Bulk Product 28cabc0f Electronics $809.18 69 0.1 37 BULK-eba207ce
22784 Bulk Product da9d9a20 Clothing $481.61 408 1.0 95 BULK-9aaea43e
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