Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

37 ms

Page Size

25

Current Page

861 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 861 Results Showing 21501 - 21525 of 24441

ID Name Category Price Stock Rating Reviews SKU
22060 Bulk Product c150f470 Sports & Outdoors $695.64 480 3.7 2 BULK-8b0d1879
22061 Bulk Product 67f2fbd8 Books $855.98 138 4.8 89 BULK-49cc7227
22062 Bulk Product 62f35c13 Books $543.26 43 0.4 60 BULK-040facbc
22063 Bulk Product af2922e0 Books $694.80 21 4.4 8 BULK-99e36183
22064 Bulk Product 160321c5 Books $207.57 104 2.4 49 BULK-058ba89d
22065 Bulk Product deab9181 Sports & Outdoors $13.69 331 4.6 54 BULK-4451b079
22066 Bulk Product 1b7dd52c Electronics $501.09 492 1.9 30 BULK-e5abb2e6
22067 Bulk Product 3551f226 Clothing $450.82 242 4.8 60 BULK-d69bf475
22068 Bulk Product e111cfc7 Toys & Games $465.92 55 0.7 84 BULK-2c93c21f
22069 Bulk Product 1a11c887 Sports & Outdoors $476.68 161 3.3 45 BULK-b2847dc9
22070 Bulk Product 72de26a3 Toys & Games $909.90 198 2.2 97 BULK-5bc9bc53
22071 Bulk Product b2c3a377 Home & Garden $380.42 168 1.2 18 BULK-b70617b1
22072 Bulk Product 6bd2093b Clothing $661.75 180 3.0 46 BULK-28885ece
22073 Bulk Product 10ff85a7 Sports & Outdoors $260.17 142 1.3 97 BULK-a6cc9ca0
22074 Bulk Product 543c146c Home & Garden $992.78 482 1.2 26 BULK-13dbd33b
22075 Bulk Product b3dc5cfb Sports & Outdoors $113.36 82 0.3 27 BULK-b559fb64
22076 Bulk Product 9b94f5d0 Sports & Outdoors $269.12 184 0.5 33 BULK-22d3073c
22077 Bulk Product 1ac7a55b Clothing $909.73 487 4.4 10 BULK-1e7cba61
22078 Bulk Product f1cff124 Clothing $749.05 201 2.0 41 BULK-342108a2
22079 Bulk Product 9e2663d6 Books $818.59 166 3.5 65 BULK-25e8728d
22080 Bulk Product 5fe1317b Home & Garden $955.22 70 2.7 36 BULK-aefd6bdf
22081 Bulk Product 8f2dd0d5 Home & Garden $36.20 87 4.6 72 BULK-4bcbd87e
22082 Bulk Product de95a406 Home & Garden $117.02 371 0.4 9 BULK-a15bfa63
22083 Bulk Product ee6cda7d Electronics $1,006.44 23 2.2 76 BULK-5ffab938
22084 Bulk Product ac554675 Books $71.53 31 0.6 94 BULK-292c7fc3
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