Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

22 ms

Page Size

25

Current Page

157 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 157 Results Showing 3901 - 3925 of 24441

ID Name Category Price Stock Rating Reviews SKU
4388 Mega Sports & Outdoors Product 2024 Sports & Outdoors $89.64 300 3.2 464 SKU-004388
4389 Elite Automotive Product 2024 Automotive $519.37 411 3.3 197 SKU-004389
4391 Pro Health & Beauty Product Pro Health & Beauty $126.22 230 4.3 607 SKU-004391
4392 Elite Sports & Outdoors Product Pro Sports & Outdoors $426.60 70 3.6 293 SKU-004392
4393 Standard Sports & Outdoors Product Advanced Sports & Outdoors $831.76 142 3.8 281 SKU-004393
4394 Standard Electronics Product Special Edition Electronics $596.57 118 3.6 769 SKU-004394
4397 Pro Home & Garden Product Special Edition Home & Garden $415.76 420 2.5 692 SKU-004397
4398 Elite Electronics Product Special Edition Electronics $162.02 436 2.7 900 SKU-004398
4399 Mega Health & Beauty Product Max Health & Beauty $477.82 149 1.4 878 SKU-004399
4400 Ultra Clothing Product Plus Clothing $650.96 90 1.8 476 SKU-004400
4401 Deluxe Electronics Product Pro Electronics $963.03 62 1.7 237 SKU-004401
4402 Economy Food & Grocery Product 2024 Food & Grocery $105.70 82 2.6 79 SKU-004402
4403 Super Automotive Product Lite Automotive $838.39 274 3.2 238 SKU-004403
4404 Professional Office Supplies Product XL Office Supplies $803.61 243 3.2 681 SKU-004404
4406 Premium Office Supplies Product Max Office Supplies $670.79 58 4.6 659 SKU-004406
4407 Standard Automotive Product Mini Automotive $567.68 149 3.0 220 SKU-004407
4408 Super Office Supplies Product Lite Office Supplies $373.82 416 1.5 828 SKU-004408
4409 Mega Office Supplies Product Lite Office Supplies $215.56 204 4.7 406 SKU-004409
4410 Super Office Supplies Product Mini Office Supplies $613.86 186 4.9 133 SKU-004410
4411 Professional Health & Beauty Product Pro Health & Beauty $690.41 173 4.7 988 SKU-004411
4412 Premium Books Product Special Edition Books $381.45 190 3.1 513 SKU-004412
4413 Elite Sports & Outdoors Product Advanced Sports & Outdoors $638.70 407 3.8 569 SKU-004413
4414 Ultra Automotive Product Max Automotive $441.43 80 3.1 609 SKU-004414
4415 Deluxe Health & Beauty Product Classic Health & Beauty $492.36 464 4.5 397 SKU-004415
4417 Deluxe Office Supplies Product Mini Office Supplies $742.49 358 3.0 621 SKU-004417
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