Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

36 ms

Page Size

25

Current Page

640 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 640 Results Showing 15976 - 16000 of 24441

ID Name Category Price Stock Rating Reviews SKU
16535 Bulk Product 5cd4f8e8 Home & Garden $678.65 341 4.3 24 BULK-3329c392
16536 Bulk Product e4d02a1d Electronics $939.34 381 0.9 70 BULK-f685f7eb
16537 Bulk Product fe9c99b4 Sports & Outdoors $608.34 486 3.8 5 BULK-58e6f78b
16538 Bulk Product ffc58274 Sports & Outdoors $87.64 305 2.9 14 BULK-b1f3a158
16539 Bulk Product e6107ba3 Home & Garden $482.99 418 4.7 24 BULK-72cae9a4
16540 Bulk Product ab4a4928 Electronics $752.11 213 4.5 31 BULK-4e361d59
16541 Bulk Product efa21678 Clothing $560.95 17 4.1 50 BULK-82f85cb2
16542 Bulk Product 3ac3d7f7 Clothing $617.43 261 1.7 84 BULK-b50d0668
16543 Bulk Product a85662a4 Clothing $954.87 67 2.8 55 BULK-11a88a2e
16544 Bulk Product 10a2c277 Home & Garden $107.61 368 4.6 62 BULK-978230f6
16545 Bulk Product e7836adc Electronics $939.48 241 0.5 32 BULK-dce1b19e
16546 Bulk Product b0b0f6d9 Electronics $960.06 246 3.8 91 BULK-58254501
16547 Bulk Product 3419056a Toys & Games $898.44 61 1.5 0 BULK-b974ed07
16548 Bulk Product c0439c60 Electronics $320.57 474 2.2 46 BULK-4b2dc7b3
16549 Bulk Product 88ed1ab0 Toys & Games $559.50 362 0.4 83 BULK-43f30399
16550 Bulk Product e52db568 Clothing $156.10 120 2.1 4 BULK-c03a9933
16551 Bulk Product 3c486ca9 Home & Garden $991.50 16 3.8 86 BULK-c91213ba
16552 Bulk Product 5f982245 Toys & Games $445.91 356 4.1 52 BULK-742eeb08
16553 Bulk Product 460113b0 Home & Garden $968.15 194 1.6 94 BULK-50bd11b8
16554 Bulk Product d40af15e Books $105.47 60 0.1 59 BULK-6bf6a05c
16555 Bulk Product 1c7195aa Sports & Outdoors $647.48 328 1.3 31 BULK-e5d53e48
16556 Bulk Product 8a78fd5d Home & Garden $560.06 197 1.4 20 BULK-a8769b2f
16557 Bulk Product 5ebc33ac Clothing $207.87 475 0.6 99 BULK-a8d1de66
16558 Bulk Product 2d321419 Clothing $604.43 59 4.1 26 BULK-d1b98513
16559 Bulk Product 6d8a803a Electronics $56.42 425 2.1 13 BULK-5762197d
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