Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

10 ms

Page Size

25

Current Page

408 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 408 Results Showing 10176 - 10200 of 24441

ID Name Category Price Stock Rating Reviews SKU
10735 Bulk Product 46979eef Books $951.56 471 0.9 46 BULK-1fce9f33
10736 Bulk Product b84d3cbc Sports & Outdoors $186.92 59 3.3 44 BULK-9ef2b6f6
10737 Bulk Product eff31ad0 Electronics $124.90 481 3.4 81 BULK-d691d484
10738 Bulk Product 3f511151 Sports & Outdoors $127.14 349 0.5 69 BULK-5c6b5ba9
10739 Bulk Product d0b8f28f Home & Garden $375.04 270 4.9 70 BULK-26802606
10740 Bulk Product 9af5c70a Toys & Games $545.35 258 4.8 9 BULK-cf75728b
10741 Bulk Product 1671c14b Sports & Outdoors $256.50 497 4.7 18 BULK-c146618f
10742 Bulk Product c2ea06e5 Sports & Outdoors $152.77 91 3.5 6 BULK-7f2410ee
10743 Bulk Product 4ff19b15 Clothing $963.94 386 3.8 46 BULK-e8369ed0
10744 Bulk Product 3aee2ac9 Home & Garden $717.26 357 0.4 69 BULK-89cca0d1
10745 Bulk Product d5ef0d8d Electronics $491.04 495 3.4 21 BULK-cd9919f1
10746 Bulk Product d58e2467 Electronics $534.53 100 2.8 43 BULK-25f027a5
10747 Bulk Product 060d4d25 Sports & Outdoors $44.99 459 3.4 90 BULK-1ee4be51
10748 Bulk Product 6f4c4e22 Electronics $443.51 15 1.5 49 BULK-a00c9d5e
10749 Bulk Product 4ccfe903 Electronics $360.14 264 2.7 38 BULK-da157509
10750 Bulk Product e12d2129 Home & Garden $525.53 231 4.8 57 BULK-0d39684f
10751 Bulk Product 0e45445d Electronics $199.37 100 1.9 17 BULK-45993b6a
10752 Bulk Product 3b14cd45 Toys & Games $422.36 402 4.4 88 BULK-5648ab5a
10753 Bulk Product fde9ed2c Toys & Games $11.87 171 1.8 21 BULK-269a2bcb
10754 Bulk Product 30db0342 Clothing $713.97 49 1.5 80 BULK-69b0897f
10755 Bulk Product 3ee82875 Toys & Games $79.09 407 4.2 81 BULK-815228a2
10756 Bulk Product 9bcccc2a Books $410.74 484 2.7 78 BULK-a2ff971a
10757 Bulk Product d25681c9 Toys & Games $165.55 46 2.5 35 BULK-5c65ff8b
10758 Bulk Product 959b0c09 Sports & Outdoors $515.06 34 3.2 71 BULK-c87475a2
10759 Bulk Product 1189022f Toys & Games $498.63 437 3.1 63 BULK-62a8b6f6
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