Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

15 ms

Page Size

25

Current Page

208 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 208 Results Showing 5176 - 5200 of 24441

ID Name Category Price Stock Rating Reviews SKU
5735 Bulk Product 3f6b5dd4 Electronics $427.70 89 1.5 34 BULK-c20a286e
5736 Bulk Product b90a314c Electronics $247.78 78 4.6 50 BULK-fe53f81a
5737 Bulk Product c9db7005 Sports & Outdoors $862.94 304 4.0 63 BULK-d0c1ae26
5738 Bulk Product e9919b9d Home & Garden $291.84 402 0.5 29 BULK-d1d1abb8
5739 Bulk Product 76c71dc7 Toys & Games $676.54 70 2.4 66 BULK-7bc9d3e6
5740 Bulk Product bae1b19f Clothing $561.80 60 2.1 8 BULK-45e8282d
5741 Bulk Product 709d12e0 Home & Garden $616.63 60 3.3 36 BULK-86bdea34
5742 Bulk Product ae07a9c2 Toys & Games $54.52 152 4.1 59 BULK-f8e2810f
5743 Bulk Product 5a788aab Electronics $233.10 121 1.4 6 BULK-a6bec22d
5744 Bulk Product 7f83b55d Electronics $917.11 324 4.1 54 BULK-b0303fef
5745 Bulk Product b7eee2a9 Books $509.37 8 4.7 69 BULK-56ee56c2
5746 Bulk Product 590620ed Books $661.09 267 2.6 46 BULK-2d59432b
5747 Bulk Product 47d25947 Books $87.05 16 1.5 6 BULK-b13aff0b
5748 Bulk Product 65c72740 Sports & Outdoors $298.36 340 3.7 95 BULK-d0ee2151
5749 Bulk Product fe5dddde Electronics $961.34 135 2.5 60 BULK-053838d7
5750 Bulk Product 0710cccf Electronics $661.66 277 4.8 16 BULK-f36994ee
5751 Bulk Product 0006fbf6 Clothing $1,004.88 136 0.7 32 BULK-13d6b162
5752 Bulk Product b329ae18 Sports & Outdoors $805.02 112 2.2 53 BULK-c6059922
5753 Bulk Product 13b0f63e Sports & Outdoors $559.93 289 0.2 57 BULK-33e4931f
5754 Bulk Product 5bfb8820 Electronics $174.71 294 4.8 35 BULK-46fd091b
5755 Bulk Product 2bb903b7 Electronics $25.78 365 4.1 30 BULK-c02deb24
5756 Bulk Product 7fabaa40 Sports & Outdoors $83.91 171 2.4 10 BULK-b40b381e
5757 Bulk Product 47ae4be9 Home & Garden $341.55 225 3.0 84 BULK-65f2fed1
5758 Bulk Product cce83c24 Clothing $724.68 281 0.7 67 BULK-7c169f7f
5759 Bulk Product f50912c2 Home & Garden $694.83 459 3.8 20 BULK-530a07dd
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