Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

10 ms

Page Size

25

Current Page

281 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 281 Results Showing 7001 - 7025 of 24441

ID Name Category Price Stock Rating Reviews SKU
7560 Bulk Product 92404f01 Home & Garden $235.73 24 2.5 20 BULK-6034c3e4
7561 Bulk Product 921fe5ba Toys & Games $230.36 469 1.4 22 BULK-210ebcbf
7562 Bulk Product 63966404 Home & Garden $385.07 119 4.3 26 BULK-30a3a2d2
7563 Bulk Product d6eb6db6 Clothing $762.50 237 4.3 50 BULK-024ca7ca
7564 Bulk Product 3e1f3b4d Home & Garden $464.39 335 2.1 90 BULK-fa2796fc
7565 Bulk Product 66a0beac Electronics $228.89 170 3.2 90 BULK-4051df64
7566 Bulk Product 1857f626 Toys & Games $613.57 31 1.4 4 BULK-c8e547f1
7567 Bulk Product 628f91b8 Toys & Games $384.53 112 1.5 4 BULK-a47672bb
7568 Bulk Product 37522dec Home & Garden $188.14 138 3.7 68 BULK-c67eb6b1
7569 Bulk Product cbe2c0fa Home & Garden $980.18 491 5.0 21 BULK-08547858
7570 Bulk Product 4ea91e69 Books $862.14 88 4.7 24 BULK-ae5d20aa
7571 Bulk Product a1f5afe6 Clothing $369.03 161 0.9 69 BULK-1229aed1
7572 Bulk Product e9984c0f Clothing $342.82 97 1.5 14 BULK-9bb28deb
7573 Bulk Product 954aae76 Home & Garden $223.33 451 0.1 18 BULK-da5628e9
7574 Bulk Product 433d510b Sports & Outdoors $883.36 269 0.7 92 BULK-640aa399
7575 Bulk Product b8ad3981 Toys & Games $370.73 377 1.3 78 BULK-bae71283
7576 Bulk Product c2930764 Toys & Games $93.00 165 4.6 53 BULK-63be1880
7577 Bulk Product 195c6652 Home & Garden $215.04 296 2.2 36 BULK-208067ce
7578 Bulk Product caf408eb Clothing $26.17 29 3.3 22 BULK-fad971b9
7579 Bulk Product 0d4c4d97 Home & Garden $745.43 339 3.3 70 BULK-197bde41
7580 Bulk Product ebc69213 Clothing $136.73 163 4.1 90 BULK-5db1db13
7581 Bulk Product cef62272 Clothing $814.73 56 2.5 87 BULK-6bb4b9f4
7582 Bulk Product 0e7d249b Toys & Games $799.88 388 3.0 73 BULK-9efcceb5
7583 Bulk Product 9a6225d8 Home & Garden $350.46 273 3.2 86 BULK-91c78d6f
7584 Bulk Product 6418f8b7 Sports & Outdoors $926.52 279 0.4 23 BULK-cb4ab8c2
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