Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

34 ms

Page Size

25

Current Page

79 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 79 Results Showing 1951 - 1975 of 24441

ID Name Category Price Stock Rating Reviews SKU
2198 Pro Food & Grocery Product Special Edition Food & Grocery $994.08 61 3.3 260 SKU-002198
2199 Standard Office Supplies Product 2024 Office Supplies $893.09 82 1.7 728 SKU-002199
2200 Deluxe Clothing Product Lite Clothing $96.49 227 4.8 242 SKU-002200
2201 Economy Books Product Plus Books $12.32 385 3.4 226 SKU-002201
2202 Economy Home & Garden Product Classic Home & Garden $516.91 344 3.3 23 SKU-002202
2204 Economy Clothing Product XL Clothing $689.01 215 4.9 575 SKU-002204
2205 Premium Food & Grocery Product 2024 Food & Grocery $588.05 264 2.9 330 SKU-002205
2206 Standard Books Product Advanced Books $129.03 322 1.2 680 SKU-002206
2207 Standard Home & Garden Product Lite Home & Garden $805.36 30 3.8 892 SKU-002207
2208 Ultra Health & Beauty Product Lite Health & Beauty $969.47 263 2.5 792 SKU-002208
2209 Economy Health & Beauty Product Plus Health & Beauty $808.24 376 3.6 933 SKU-002209
2210 Standard Automotive Product Classic Automotive $71.57 58 4.1 457 SKU-002210
2212 Standard Automotive Product Advanced Automotive $476.15 278 2.5 589 SKU-002212
2213 Elite Books Product Max Books $193.21 194 2.9 498 SKU-002213
2214 Professional Books Product Pro Books $17.93 259 4.9 199 SKU-002214
2215 Economy Toys & Games Product Pro Toys & Games $130.86 298 1.5 444 SKU-002215
2216 Deluxe Automotive Product Mini Automotive $999.12 62 4.2 877 SKU-002216
2217 Economy Automotive Product Plus Automotive $310.72 146 1.4 758 SKU-002217
2218 Deluxe Automotive Product Pro Automotive $168.61 382 3.6 171 SKU-002218
2219 Elite Books Product Lite Books $986.07 404 4.5 497 SKU-002219
2220 Standard Toys & Games Product XL Toys & Games $125.55 307 2.2 694 SKU-002220
2221 Mega Clothing Product XL Clothing $631.89 477 2.4 265 SKU-002221
2222 Professional Home & Garden Product XL Home & Garden $509.03 97 3.0 292 SKU-002222
2223 Ultra Food & Grocery Product Classic Food & Grocery $201.94 240 1.1 744 SKU-002223
2224 Deluxe Home & Garden Product Mini Home & Garden $778.33 101 1.3 781 SKU-002224
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