Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

39 ms

Page Size

25

Current Page

275 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 275 Results Showing 6851 - 6875 of 24441

ID Name Category Price Stock Rating Reviews SKU
7410 Bulk Product 0b249076 Books $73.84 441 2.8 87 BULK-043af8aa
7411 Bulk Product 08b91c1f Electronics $514.53 339 1.4 12 BULK-796406a6
7412 Bulk Product e8c6ce59 Toys & Games $267.36 459 1.5 40 BULK-6f832aec
7413 Bulk Product ff048c57 Sports & Outdoors $116.21 102 3.7 20 BULK-63d624a6
7414 Bulk Product b89e5ed9 Sports & Outdoors $245.58 109 4.2 2 BULK-685454af
7415 Bulk Product a1ecc29d Books $140.89 27 2.9 21 BULK-07658786
7416 Bulk Product 372904b0 Clothing $843.90 189 4.7 81 BULK-2f0bab06
7417 Bulk Product 2e3b9c8f Home & Garden $276.56 399 4.0 61 BULK-7817d41e
7418 Bulk Product a601a97d Home & Garden $324.94 402 4.7 64 BULK-05145354
7419 Bulk Product fe5b14b3 Clothing $711.94 225 2.2 68 BULK-c56a2783
7420 Bulk Product f6f7a58f Electronics $724.93 356 4.8 76 BULK-40e40168
7421 Bulk Product b8212e3d Books $849.69 465 0.2 35 BULK-ac65bd52
7422 Bulk Product 5e75b7f8 Home & Garden $301.85 32 2.2 48 BULK-72d1cbb0
7423 Bulk Product 2ca91a9c Home & Garden $745.19 268 4.5 10 BULK-10932aac
7424 Bulk Product 95f06651 Electronics $874.37 300 0.5 42 BULK-ffef6bc0
7425 Bulk Product 2c45adf8 Books $952.97 26 4.3 95 BULK-4ae1bc39
7426 Bulk Product bfd21532 Home & Garden $147.65 425 1.8 14 BULK-1c225a9d
7427 Bulk Product 4924cdd1 Books $411.90 347 4.3 48 BULK-00e38d48
7428 Bulk Product adbe6332 Home & Garden $519.44 7 1.9 87 BULK-83eac106
7429 Bulk Product 55223159 Clothing $741.05 256 4.9 4 BULK-bd537b4d
7430 Bulk Product 2ec37f2e Toys & Games $941.02 99 4.0 45 BULK-a54bb382
7431 Bulk Product eb4fc0a5 Sports & Outdoors $865.74 424 3.5 48 BULK-92ea0683
7432 Bulk Product 22da3bb7 Clothing $185.52 459 4.5 51 BULK-fe853161
7433 Bulk Product 92761e59 Home & Garden $435.81 230 4.1 24 BULK-78ce9a2f
7434 Bulk Product ce1853cb Sports & Outdoors $507.76 174 1.4 55 BULK-395a3bb5
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