Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

37 ms

Page Size

25

Current Page

421 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 421 Results Showing 10501 - 10525 of 24441

ID Name Category Price Stock Rating Reviews SKU
11060 Bulk Product e763dbac Toys & Games $493.02 462 1.4 78 BULK-3c29b65c
11061 Bulk Product e2f71eb1 Sports & Outdoors $333.34 351 4.3 20 BULK-ca8bad60
11062 Bulk Product dd1ed981 Books $822.17 270 2.6 55 BULK-243db79a
11063 Bulk Product 39d8bdd3 Clothing $896.65 244 3.7 0 BULK-d7167cb8
11064 Bulk Product b8c6aa34 Home & Garden $544.03 432 1.1 45 BULK-81057145
11065 Bulk Product e32cee37 Toys & Games $361.65 26 0.3 3 BULK-be4085af
11066 Bulk Product 4fd289e2 Electronics $336.13 473 3.2 40 BULK-3578a486
11067 Bulk Product dd67bf13 Clothing $290.39 288 0.8 94 BULK-a0e14628
11068 Bulk Product 4a6e8d0c Electronics $303.36 236 4.4 58 BULK-418f5987
11069 Bulk Product ae138d7d Home & Garden $366.32 169 0.4 35 BULK-d3244050
11070 Bulk Product 5ce5cd86 Books $243.91 388 3.9 9 BULK-b6e002a2
11071 Bulk Product 360cfd33 Books $419.62 21 3.3 12 BULK-db9643d5
11072 Bulk Product c75cd26f Toys & Games $961.65 454 0.1 13 BULK-f404bddc
11073 Bulk Product 6e7bb8c2 Home & Garden $56.76 317 3.5 87 BULK-af537878
11074 Bulk Product 1f7d4894 Toys & Games $547.29 499 1.0 59 BULK-91e67866
11075 Bulk Product d37843fa Clothing $572.89 212 2.6 49 BULK-81f1e1e4
11076 Bulk Product b0ff805c Sports & Outdoors $261.35 464 3.6 6 BULK-7333e195
11077 Bulk Product 2409864a Electronics $407.86 164 1.9 32 BULK-ce8e1aac
11078 Bulk Product 5b6afae6 Home & Garden $484.93 316 0.0 22 BULK-b277242b
11079 Bulk Product a647e065 Clothing $419.47 35 4.1 64 BULK-816c69cc
11080 Bulk Product c5d5beef Toys & Games $346.64 36 3.7 16 BULK-713ce42c
11081 Bulk Product 41db0c38 Toys & Games $584.14 300 1.4 18 BULK-e0f415e3
11082 Bulk Product 49586eec Home & Garden $79.38 236 2.6 51 BULK-99c594aa
11083 Bulk Product 9878f322 Sports & Outdoors $59.94 423 3.1 87 BULK-f53b42bf
11084 Bulk Product 8950a7fa Clothing $327.10 75 4.6 67 BULK-11f3ac59
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