Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

28 ms

Page Size

25

Current Page

724 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 724 Results Showing 18076 - 18100 of 24441

ID Name Category Price Stock Rating Reviews SKU
18635 Bulk Product aebc6522 Books $173.87 65 4.7 39 BULK-f7a79021
18636 Bulk Product 90023d92 Books $491.16 93 0.6 56 BULK-0bc731cc
18637 Bulk Product 638f8500 Toys & Games $792.14 263 3.0 52 BULK-2c76aeab
18638 Bulk Product a5fa9045 Home & Garden $651.75 474 4.9 84 BULK-a146aeb8
18639 Bulk Product 856b2cfc Sports & Outdoors $948.36 53 3.2 89 BULK-c1030ab8
18640 Bulk Product 984ef24e Electronics $287.16 379 0.8 92 BULK-49a647cc
18641 Bulk Product 426fe00c Books $602.39 11 2.6 36 BULK-86380d1a
18642 Bulk Product 0b43e3f6 Sports & Outdoors $224.34 61 4.2 57 BULK-1d259cf4
18643 Bulk Product 3a0bd61f Clothing $187.03 161 0.0 29 BULK-5a8dabf6
18644 Bulk Product ef765197 Home & Garden $60.95 172 0.8 80 BULK-f4a4e795
18645 Bulk Product 5885a458 Books $289.15 453 0.9 39 BULK-9bfba133
18646 Bulk Product 08385c59 Home & Garden $847.72 240 2.7 51 BULK-0ec870a8
18647 Bulk Product 9b978851 Books $587.20 307 2.2 34 BULK-4ae781c4
18648 Bulk Product 7315712b Home & Garden $273.40 52 5.0 86 BULK-6a3c6853
18649 Bulk Product 768f559a Clothing $165.87 436 3.7 26 BULK-a1e91b1a
18650 Bulk Product e87b8068 Books $257.59 307 0.4 21 BULK-d10277fd
18651 Bulk Product aff34fa9 Home & Garden $113.61 453 4.6 86 BULK-035f82b3
18652 Bulk Product 53848ded Toys & Games $226.37 212 2.4 27 BULK-37bbe3fc
18653 Bulk Product 7ca5144e Home & Garden $306.82 499 4.0 45 BULK-a7827872
18654 Bulk Product 567ab870 Electronics $254.53 25 0.1 17 BULK-a5f60e90
18655 Bulk Product 6e0f5da2 Clothing $822.75 65 4.6 51 BULK-236d50d1
18656 Bulk Product a54d8265 Sports & Outdoors $839.21 183 0.8 92 BULK-32eeb608
18657 Bulk Product 074f6c7b Books $667.57 363 4.4 24 BULK-61fd9283
18658 Bulk Product c6fe7a2d Sports & Outdoors $377.79 56 2.9 26 BULK-9e2af1a6
18659 Bulk Product 10a5dab4 Toys & Games $404.84 388 1.8 22 BULK-29b6d725
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