Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

17 ms

Page Size

25

Current Page

969 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 969 Results Showing 24201 - 24225 of 24441

ID Name Category Price Stock Rating Reviews SKU
24760 Bulk Product ea62d6ec Books $498.37 495 1.7 24 BULK-becf3b88
24761 Bulk Product a8f87cc0 Books $93.98 367 1.5 36 BULK-c353d0b5
24762 Bulk Product 07671877 Electronics $268.24 154 0.7 31 BULK-1f21d159
24763 Bulk Product e55a4758 Sports & Outdoors $970.04 74 4.7 70 BULK-31f140bd
24764 Bulk Product b403da8b Electronics $272.33 237 1.4 37 BULK-453651bf
24765 Bulk Product 635bf88e Electronics $997.73 359 3.0 96 BULK-e347fb26
24766 Bulk Product 754d298e Books $268.31 3 3.7 47 BULK-e75aee99
24767 Bulk Product e8d8d37c Electronics $580.00 78 1.4 63 BULK-b9eef3f6
24768 Bulk Product fd6423a0 Toys & Games $692.21 111 3.9 9 BULK-cd936185
24769 Bulk Product a9072441 Clothing $984.66 8 2.1 42 BULK-5d845589
24770 Bulk Product 06b813cb Sports & Outdoors $331.30 245 2.9 40 BULK-defb3e7b
24771 Bulk Product 838a5f0e Toys & Games $189.96 361 1.0 29 BULK-3175dc18
24772 Bulk Product 7c1c43c2 Books $900.69 103 0.8 21 BULK-8fc4a668
24773 Bulk Product eb1a47dc Clothing $118.36 322 4.9 70 BULK-b72c4106
24774 Bulk Product 01785ba1 Home & Garden $66.17 264 2.6 59 BULK-faffecbf
24775 Bulk Product 95d4efaf Books $482.96 419 1.1 34 BULK-3640fb7d
24776 Bulk Product 77338da8 Books $112.48 6 2.8 3 BULK-869343aa
24777 Bulk Product aaf04053 Toys & Games $931.17 335 4.3 2 BULK-4257ec73
24778 Bulk Product 59ba9576 Home & Garden $536.46 37 1.1 6 BULK-71d327e6
24779 Bulk Product 05d392e8 Electronics $186.16 155 4.6 54 BULK-b5165f22
24780 Bulk Product a7247e67 Electronics $225.32 475 5.0 54 BULK-45a840ee
24781 Bulk Product e5c7fde4 Sports & Outdoors $704.95 91 4.0 41 BULK-138cd65c
24782 Bulk Product a17b061f Electronics $796.97 175 4.5 97 BULK-e3f7393a
24783 Bulk Product c6ad9983 Home & Garden $876.11 440 0.6 80 BULK-c77befaf
24784 Bulk Product c62857dd Electronics $876.55 140 4.2 63 BULK-bf85a836
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