Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

17 ms

Page Size

25

Current Page

478 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 478 Results Showing 11926 - 11950 of 24441

ID Name Category Price Stock Rating Reviews SKU
12485 Bulk Product 1d412436 Books $862.26 135 3.7 47 BULK-f7de7505
12486 Bulk Product 0dc178f0 Sports & Outdoors $729.49 59 3.7 36 BULK-9d2ca56e
12487 Bulk Product afaec45c Home & Garden $449.03 20 1.1 65 BULK-87dbd68a
12488 Bulk Product 267b0405 Books $917.82 184 2.2 50 BULK-d243bea9
12489 Bulk Product 6b2edc01 Home & Garden $133.05 468 2.1 74 BULK-949e61f5
12490 Bulk Product c4af50b9 Books $422.94 57 1.0 89 BULK-c06073c9
12491 Bulk Product cb24fefc Sports & Outdoors $783.77 235 0.8 49 BULK-c26d5376
12492 Bulk Product d8d57f9d Home & Garden $973.77 479 2.7 55 BULK-081a8e0a
12493 Bulk Product 0487a1aa Toys & Games $902.07 16 2.2 80 BULK-e46c97c8
12494 Bulk Product 0409a501 Toys & Games $145.44 298 1.5 96 BULK-8b8d4e59
12495 Bulk Product 1bf9d778 Electronics $321.53 387 0.6 25 BULK-fc32cc5b
12496 Bulk Product 21641f4a Books $968.02 479 1.5 29 BULK-1e8b974c
12497 Bulk Product b544292e Sports & Outdoors $323.72 141 2.2 64 BULK-51ed2bf1
12498 Bulk Product 5fb1c682 Books $877.39 129 4.2 74 BULK-b61b395e
12499 Bulk Product b125d979 Home & Garden $598.27 475 3.2 35 BULK-d8170321
12500 Bulk Product 293fecdb Clothing $281.72 298 0.7 42 BULK-7c4d7663
12501 Bulk Product 8ed31d9f Clothing $204.78 474 3.6 62 BULK-a327761e
12502 Bulk Product 020e1680 Clothing $944.18 332 2.1 46 BULK-76ba1cd1
12503 Bulk Product 18c9ad2e Toys & Games $811.85 18 3.4 54 BULK-82fef43f
12504 Bulk Product ae9949e0 Electronics $180.50 1 0.1 21 BULK-dbed6248
12505 Bulk Product a232d3d0 Home & Garden $252.30 133 2.6 57 BULK-8557ea96
12506 Bulk Product 30bf7dcf Clothing $554.44 75 3.8 16 BULK-b5726487
12507 Bulk Product 48a09d91 Home & Garden $903.54 85 4.6 47 BULK-18093a72
12508 Bulk Product 3d0be94d Home & Garden $761.84 352 1.5 94 BULK-5a5262dd
12509 Bulk Product c8a63e95 Toys & Games $423.68 139 4.1 22 BULK-0114f0aa
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