Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

23 ms

Page Size

25

Current Page

641 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 641 Results Showing 16001 - 16025 of 24441

ID Name Category Price Stock Rating Reviews SKU
16560 Bulk Product 798b3079 Electronics $457.00 203 1.7 19 BULK-29ff118e
16561 Bulk Product 9217db0a Electronics $570.76 413 2.3 16 BULK-f7635e69
16562 Bulk Product c33c086f Electronics $274.73 6 2.6 16 BULK-af041813
16563 Bulk Product 33fd198d Toys & Games $647.93 164 1.3 96 BULK-d0ff0e48
16564 Bulk Product ad43972a Electronics $803.81 354 1.2 23 BULK-c982ecd0
16565 Bulk Product 76e47549 Toys & Games $1,009.25 322 3.5 98 BULK-d1cbf8c5
16566 Bulk Product 8c30ee1a Electronics $68.83 59 4.7 28 BULK-31eed51f
16567 Bulk Product 62bc9db3 Books $729.33 279 3.9 95 BULK-35acd17a
16568 Bulk Product 1ea41afa Electronics $13.59 363 3.3 51 BULK-7fbacf55
16569 Bulk Product 0cadd404 Home & Garden $845.30 152 2.2 84 BULK-1e9ff33e
16570 Bulk Product 98f7bcab Books $671.64 318 0.6 90 BULK-9532b247
16571 Bulk Product 875b02b0 Home & Garden $10.40 232 2.1 90 BULK-b351c456
16572 Bulk Product d91fa9f6 Electronics $35.47 28 4.7 39 BULK-a0f1b2ec
16573 Bulk Product 6c0f18eb Electronics $975.69 255 1.3 8 BULK-168a91b0
16574 Bulk Product e032da77 Toys & Games $890.31 55 0.7 25 BULK-b8522af7
16575 Bulk Product b5b01e2d Toys & Games $571.15 471 4.9 99 BULK-729e32ef
16576 Bulk Product 86bd806a Sports & Outdoors $511.68 405 2.5 66 BULK-00e75718
16577 Bulk Product db759855 Electronics $942.17 299 3.6 15 BULK-0749d1c2
16578 Bulk Product dc4b136f Electronics $254.16 165 1.6 35 BULK-a899e3f1
16579 Bulk Product 2271ab0e Toys & Games $320.94 442 3.6 97 BULK-e7bd44eb
16580 Bulk Product 36aafadc Electronics $289.94 237 4.3 50 BULK-53a7403e
16581 Bulk Product a7b6a1b1 Toys & Games $74.53 336 1.2 95 BULK-4afe8b9f
16582 Bulk Product a3bef46b Clothing $768.16 152 0.7 37 BULK-16b32064
16583 Bulk Product 061f1470 Home & Garden $808.70 15 4.2 8 BULK-6e9a46a8
16584 Bulk Product 2329e07a Sports & Outdoors $353.17 102 4.2 71 BULK-9b1cd6f3
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