Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

17 ms

Page Size

25

Current Page

629 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 629 Results Showing 15701 - 15725 of 24441

ID Name Category Price Stock Rating Reviews SKU
16260 Bulk Product 8b1dc07d Clothing $321.45 350 4.7 67 BULK-32ca002a
16261 Bulk Product a761619c Home & Garden $52.03 160 3.6 68 BULK-496f06f7
16262 Bulk Product 41c9567a Toys & Games $672.55 490 2.6 11 BULK-a1fb58fd
16263 Bulk Product 96524c95 Home & Garden $343.79 467 2.7 70 BULK-5e37613f
16264 Bulk Product a543c608 Sports & Outdoors $681.47 235 3.8 94 BULK-b894e2c6
16265 Bulk Product 8df66bce Books $829.98 455 2.7 35 BULK-050497c1
16266 Bulk Product 7fd37c2a Home & Garden $877.76 393 4.6 61 BULK-6a4579cd
16267 Bulk Product 2e78605f Books $977.21 353 0.0 23 BULK-63bbeb10
16268 Bulk Product 76de0454 Sports & Outdoors $917.34 445 3.9 33 BULK-9108845f
16269 Bulk Product 27815715 Home & Garden $521.20 352 2.9 62 BULK-70821e8a
16270 Bulk Product 26ba032c Sports & Outdoors $425.83 369 4.9 75 BULK-0b385f83
16271 Bulk Product 3c8ecef5 Home & Garden $345.87 178 3.3 57 BULK-52651991
16272 Bulk Product ef57dd9d Electronics $908.40 344 3.0 6 BULK-4bcbf907
16273 Bulk Product af6026e4 Electronics $346.83 282 3.1 56 BULK-3c437248
16274 Bulk Product 1fe17731 Clothing $87.31 181 3.5 19 BULK-4065176d
16275 Bulk Product 3fb81c06 Toys & Games $224.44 407 0.9 43 BULK-d2caa3b0
16276 Bulk Product bd591e96 Electronics $875.87 421 4.3 97 BULK-5bdf2af9
16277 Bulk Product fd69dee9 Electronics $390.90 437 0.8 10 BULK-06221eab
16278 Bulk Product 24dd62b2 Home & Garden $813.43 263 0.2 47 BULK-85528bdb
16279 Bulk Product d84ba002 Books $779.52 223 2.1 76 BULK-b5cc4fd0
16280 Bulk Product c54654dc Home & Garden $495.52 39 0.2 77 BULK-f88f542d
16281 Bulk Product b8119abd Clothing $58.47 41 4.8 75 BULK-4b0804ff
16282 Bulk Product 9046a01f Home & Garden $623.81 410 1.2 54 BULK-ec2b93df
16283 Bulk Product 96611a27 Electronics $559.49 405 1.0 30 BULK-e1f333ec
16284 Bulk Product f0a60a10 Sports & Outdoors $848.53 416 4.0 57 BULK-bd6a2ad5
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