Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

14 ms

Page Size

25

Current Page

76 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 76 Results Showing 1876 - 1900 of 24441

ID Name Category Price Stock Rating Reviews SKU
2118 Economy Sports & Outdoors Product Plus Sports & Outdoors $350.03 423 5.0 871 SKU-002118
2119 Elite Sports & Outdoors Product Special Edition Sports & Outdoors $211.93 73 1.9 670 SKU-002119
2120 Economy Toys & Games Product Max Toys & Games $47.68 34 1.6 426 SKU-002120
2121 Deluxe Toys & Games Product Lite Toys & Games $196.78 21 3.5 789 SKU-002121
2122 Premium Home & Garden Product Special Edition Home & Garden $405.14 377 3.8 367 SKU-002122
2123 Deluxe Automotive Product 2024 Automotive $483.83 250 1.6 990 SKU-002123
2124 Economy Sports & Outdoors Product Advanced Sports & Outdoors $767.49 185 4.8 176 SKU-002124
2125 Ultra Toys & Games Product Lite Toys & Games $460.94 402 2.2 359 SKU-002125
2126 Ultra Automotive Product Mini Automotive $213.29 465 4.5 879 SKU-002126
2128 Elite Books Product Pro Books $871.64 279 2.0 344 SKU-002128
2129 Deluxe Electronics Product Lite Electronics $528.12 359 3.3 134 SKU-002129
2130 Super Food & Grocery Product Plus Food & Grocery $163.68 240 2.1 456 SKU-002130
2131 Standard Automotive Product Special Edition Automotive $921.28 27 1.0 963 SKU-002131
2132 Pro Books Product Pro Books $907.04 498 4.9 311 SKU-002132
2133 Economy Clothing Product Lite Clothing $423.25 382 2.7 294 SKU-002133
2134 Ultra Clothing Product 2024 Clothing $982.29 175 1.9 578 SKU-002134
2135 Ultra Clothing Product Max Clothing $714.21 3 4.4 867 SKU-002135
2136 Mega Electronics Product Lite Electronics $391.82 46 2.9 370 SKU-002136
2137 Deluxe Books Product Pro Books $417.71 232 3.0 480 SKU-002137
2138 Standard Sports & Outdoors Product Plus Sports & Outdoors $103.49 279 1.9 337 SKU-002138
2139 Pro Health & Beauty Product Max Health & Beauty $118.41 83 1.1 432 SKU-002139
2140 Premium Home & Garden Product Mini Home & Garden $520.57 251 2.0 124 SKU-002140
2141 Mega Home & Garden Product XL Home & Garden $325.86 107 3.9 156 SKU-002141
2142 Pro Home & Garden Product Classic Home & Garden $691.30 80 3.4 394 SKU-002142
2143 Premium Automotive Product Pro Automotive $777.81 78 1.8 997 SKU-002143
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