Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

8 ms

Page Size

25

Current Page

81 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 81 Results Showing 2001 - 2025 of 24441

ID Name Category Price Stock Rating Reviews SKU
2250 Standard Food & Grocery Product XL Food & Grocery $529.69 72 2.6 674 SKU-002250
2252 Super Home & Garden Product Classic Home & Garden $602.16 310 3.2 919 SKU-002252
2253 Economy Clothing Product Special Edition Clothing $914.28 373 4.3 593 SKU-002253
2254 Premium Clothing Product Pro Clothing $498.04 132 1.6 895 SKU-002254
2255 Professional Books Product 2024 Books $421.84 106 1.6 897 SKU-002255
2256 Standard Books Product XL Books $200.25 200 4.9 262 SKU-002256
2257 Ultra Office Supplies Product Special Edition Office Supplies $835.04 35 4.2 55 SKU-002257
2258 Super Toys & Games Product Lite Toys & Games $272.29 274 2.2 992 SKU-002258
2259 Elite Sports & Outdoors Product Lite Sports & Outdoors $621.25 486 1.7 184 SKU-002259
2260 Professional Clothing Product Classic Clothing $87.64 379 3.2 264 SKU-002260
2261 Elite Books Product 2024 Books $724.48 200 4.9 660 SKU-002261
2262 Mega Books Product Max Books $950.04 473 4.3 578 SKU-002262
2263 Deluxe Sports & Outdoors Product Pro Sports & Outdoors $278.26 274 4.7 213 SKU-002263
2264 Standard Automotive Product Advanced Automotive $664.67 287 3.8 599 SKU-002264
2266 Deluxe Electronics Product Classic Electronics $780.66 499 1.2 471 SKU-002266
2267 Deluxe Toys & Games Product 2024 Toys & Games $301.00 444 3.3 497 SKU-002267
2268 Professional Electronics Product Classic Electronics $297.15 94 4.2 208 SKU-002268
2269 Premium Home & Garden Product Pro Home & Garden $689.32 414 4.3 278 SKU-002269
2270 Super Health & Beauty Product Lite Health & Beauty $531.57 230 2.0 59 SKU-002270
2271 Super Sports & Outdoors Product XL Sports & Outdoors $761.92 467 2.1 909 SKU-002271
2272 Deluxe Clothing Product Mini Clothing $820.21 230 2.9 403 SKU-002272
2273 Standard Books Product XL Books $459.51 495 2.9 176 SKU-002273
2274 Economy Sports & Outdoors Product Advanced Sports & Outdoors $362.08 106 3.6 302 SKU-002274
2275 Mega Books Product Plus Books $614.44 79 3.7 35 SKU-002275
2276 Ultra Clothing Product Plus Clothing $501.15 361 4.3 250 SKU-002276
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