Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

14 ms

Page Size

25

Current Page

967 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 967 Results Showing 24151 - 24175 of 24441

ID Name Category Price Stock Rating Reviews SKU
24710 Bulk Product 572a4bd3 Electronics $592.85 312 0.1 55 BULK-f287f25b
24711 Bulk Product 08819a5f Books $887.84 436 0.6 11 BULK-28cfa2e3
24712 Bulk Product 4239abd6 Home & Garden $770.54 328 0.1 28 BULK-6bfb26be
24713 Bulk Product a1bd0b5a Books $866.03 269 1.4 23 BULK-32b94361
24714 Bulk Product 3f4f3430 Toys & Games $660.58 203 4.1 46 BULK-8848635a
24715 Bulk Product 54a557a2 Clothing $704.56 343 0.3 47 BULK-5a9695d7
24716 Bulk Product ae227e0c Electronics $810.50 411 1.9 25 BULK-bdc76795
24717 Bulk Product 4a826322 Electronics $866.59 352 4.1 21 BULK-9dd421b8
24718 Bulk Product 88fedad0 Home & Garden $365.86 203 4.4 34 BULK-6615674d
24719 Bulk Product 15132a88 Electronics $530.71 76 2.9 35 BULK-363b7d1e
24720 Bulk Product 85ae4fa7 Electronics $167.53 81 3.7 65 BULK-228d0073
24721 Bulk Product c7bd6e94 Home & Garden $618.56 171 4.6 74 BULK-078d01fc
24722 Bulk Product 14f31d2f Home & Garden $446.05 356 2.6 68 BULK-24e94774
24723 Bulk Product b07ea1b6 Toys & Games $317.10 476 0.6 39 BULK-5450cac1
24724 Bulk Product e1b5f3c9 Clothing $961.13 38 4.2 53 BULK-1af063c0
24725 Bulk Product 5ad4f7ac Toys & Games $482.00 12 3.7 28 BULK-eb861c7e
24726 Bulk Product 5e1c58e3 Home & Garden $101.38 177 4.7 82 BULK-6661219b
24727 Bulk Product 6bb9cb69 Sports & Outdoors $11.04 179 1.0 77 BULK-6db76db8
24728 Bulk Product 242a6e11 Clothing $794.71 410 0.5 35 BULK-7e988af6
24729 Bulk Product 4271783d Clothing $619.11 225 3.6 47 BULK-2b16d922
24730 Bulk Product 94ccfbec Sports & Outdoors $344.72 36 1.0 13 BULK-aed93e73
24731 Bulk Product c542d778 Toys & Games $411.85 470 1.4 9 BULK-52c99df9
24732 Bulk Product 6cfa5e8d Toys & Games $366.92 355 0.3 23 BULK-a0736b85
24733 Bulk Product 3332692c Electronics $114.50 13 1.1 8 BULK-bc330035
24734 Bulk Product 83f52e43 Clothing $594.78 330 2.2 93 BULK-e9bff9c3
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