Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

42 ms

Page Size

25

Current Page

443 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 443 Results Showing 11051 - 11075 of 24441

ID Name Category Price Stock Rating Reviews SKU
11610 Bulk Product 582ff215 Electronics $949.65 40 3.1 13 BULK-fcb7f55a
11611 Bulk Product d67f6eba Electronics $482.62 17 3.6 30 BULK-3757c640
11612 Bulk Product 72e41382 Electronics $659.08 213 2.9 36 BULK-c246bbf6
11613 Bulk Product d42f9404 Books $596.79 37 4.3 20 BULK-8cccdcc7
11614 Bulk Product 69c8cc89 Sports & Outdoors $516.23 164 1.8 87 BULK-f7d662ac
11615 Bulk Product d3e10399 Toys & Games $11.64 358 2.5 55 BULK-e207a33d
11616 Bulk Product fd730bee Electronics $135.34 20 1.9 68 BULK-c9bac87b
11617 Bulk Product 4f3e1424 Books $747.22 347 1.4 51 BULK-6472aa00
11618 Bulk Product 8ed6534b Home & Garden $885.51 321 4.8 25 BULK-8ece5e6d
11619 Bulk Product 663c4250 Books $668.34 468 2.8 71 BULK-a678ab8c
11620 Bulk Product f00a3839 Home & Garden $417.25 239 0.4 85 BULK-2db2ad51
11621 Bulk Product e967464e Electronics $928.42 489 0.3 62 BULK-fb313e37
11622 Bulk Product 21c4a586 Sports & Outdoors $546.31 408 2.0 80 BULK-bf815083
11623 Bulk Product 18e0f3c2 Home & Garden $450.97 470 0.2 80 BULK-774133b0
11624 Bulk Product eeec0351 Sports & Outdoors $959.32 199 0.4 27 BULK-877fde2d
11625 Bulk Product d7ff7d6c Books $262.21 260 0.4 50 BULK-bbfd46d4
11626 Bulk Product 80603eeb Books $289.45 106 0.3 2 BULK-adabb83b
11627 Bulk Product f5daadd0 Sports & Outdoors $469.89 483 2.6 98 BULK-f1ccd858
11628 Bulk Product b393eab2 Clothing $457.18 36 4.4 99 BULK-43b56b1b
11629 Bulk Product 1cc88125 Clothing $326.51 85 0.6 5 BULK-eb293df5
11630 Bulk Product 1137d561 Books $536.06 29 4.3 30 BULK-380c0b82
11631 Bulk Product 6bc9326d Sports & Outdoors $362.79 300 1.3 43 BULK-cd033620
11632 Bulk Product 7bc9c848 Sports & Outdoors $306.71 168 3.2 98 BULK-95b92765
11633 Bulk Product 1775908f Electronics $193.92 312 4.4 81 BULK-e4656933
11634 Bulk Product 79b6f2f5 Home & Garden $914.86 265 1.0 10 BULK-3ce0d1d7
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