Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

40 ms

Page Size

25

Current Page

82 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 82 Results Showing 2026 - 2050 of 24441

ID Name Category Price Stock Rating Reviews SKU
2277 Professional Home & Garden Product Max Home & Garden $798.34 29 4.7 588 SKU-002277
2278 Elite Office Supplies Product Plus Office Supplies $454.98 291 4.8 523 SKU-002278
2279 Super Food & Grocery Product Special Edition Food & Grocery $385.64 291 3.3 505 SKU-002279
2280 Pro Health & Beauty Product Pro Health & Beauty $837.74 203 2.1 754 SKU-002280
2281 Ultra Sports & Outdoors Product Pro Sports & Outdoors $166.80 359 4.1 6 SKU-002281
2282 Professional Books Product Lite Books $704.08 115 2.1 741 SKU-002282
2283 Super Toys & Games Product Advanced Toys & Games $739.41 341 3.1 262 SKU-002283
2284 Economy Food & Grocery Product 2024 Food & Grocery $381.10 107 4.4 272 SKU-002284
2285 Premium Health & Beauty Product Mini Health & Beauty $759.49 268 4.9 602 SKU-002285
2286 Pro Clothing Product Advanced Clothing $163.46 123 1.6 708 SKU-002286
2288 Elite Food & Grocery Product Plus Food & Grocery $471.76 172 3.8 88 SKU-002288
2289 Professional Toys & Games Product Lite Toys & Games $85.22 447 3.9 911 SKU-002289
2290 Mega Electronics Product Pro Electronics $133.77 60 1.6 494 SKU-002290
2291 Elite Books Product Advanced Books $23.72 116 2.3 394 SKU-002291
2292 Elite Food & Grocery Product Special Edition Food & Grocery $890.43 370 2.9 487 SKU-002292
2294 Mega Home & Garden Product 2024 Home & Garden $83.25 205 3.1 972 SKU-002294
2296 Premium Home & Garden Product 2024 Home & Garden $379.96 238 3.4 757 SKU-002296
2298 Economy Automotive Product 2024 Automotive $27.99 367 1.2 965 SKU-002298
2299 Economy Health & Beauty Product Plus Health & Beauty $891.92 368 4.3 922 SKU-002299
2300 Mega Toys & Games Product Plus Toys & Games $723.69 402 2.6 326 SKU-002300
2301 Professional Office Supplies Product 2024 Office Supplies $510.01 234 2.8 6 SKU-002301
2302 Mega Books Product Plus Books $877.67 158 2.2 867 SKU-002302
2303 Super Clothing Product Lite Clothing $638.46 5 1.5 836 SKU-002303
2304 Economy Sports & Outdoors Product Pro Sports & Outdoors $607.87 451 4.0 645 SKU-002304
2305 Standard Clothing Product Classic Clothing $387.57 263 4.1 783 SKU-002305
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