Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

16 ms

Page Size

25

Current Page

644 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 644 Results Showing 16076 - 16100 of 24441

ID Name Category Price Stock Rating Reviews SKU
16635 Bulk Product 991675b4 Sports & Outdoors $674.45 145 4.7 81 BULK-a4ad5509
16636 Bulk Product 3c564f3a Home & Garden $185.96 371 4.0 33 BULK-afa24015
16637 Bulk Product 7f52c21d Sports & Outdoors $262.58 62 3.1 27 BULK-5fe146b9
16638 Bulk Product 1d981a10 Sports & Outdoors $989.69 179 1.5 66 BULK-a808c285
16639 Bulk Product 3b139c44 Electronics $926.10 181 4.7 60 BULK-885d9791
16640 Bulk Product 830452c9 Sports & Outdoors $804.96 48 1.7 64 BULK-a2ae045c
16641 Bulk Product c2ac8356 Clothing $69.21 204 1.4 82 BULK-a857a559
16642 Bulk Product 30a69e9e Toys & Games $888.27 25 1.6 34 BULK-c28d22a2
16643 Bulk Product cd0d526b Books $433.62 440 2.9 17 BULK-cc78f00f
16644 Bulk Product d59644f6 Sports & Outdoors $81.46 97 1.7 26 BULK-c0fad0f3
16645 Bulk Product 35ed7db2 Electronics $560.53 69 4.0 19 BULK-43fa6c96
16646 Bulk Product 8610154e Books $782.15 348 4.7 67 BULK-af0986f4
16647 Bulk Product dea438bf Home & Garden $107.39 367 0.8 15 BULK-60325f51
16648 Bulk Product c02817c0 Home & Garden $815.03 35 0.2 90 BULK-3466c6ef
16649 Bulk Product 25c17003 Electronics $303.98 14 4.3 11 BULK-c606ef8c
16650 Bulk Product c92bff4a Clothing $144.10 24 0.6 9 BULK-377549d5
16651 Bulk Product 8a20c982 Toys & Games $706.82 274 3.6 4 BULK-dcf6aaf5
16652 Bulk Product 7c8b8558 Clothing $206.97 7 0.7 22 BULK-6b9f1460
16653 Bulk Product 06e2f973 Electronics $431.44 234 3.1 82 BULK-6538a920
16654 Bulk Product 57e14586 Clothing $629.62 168 2.7 42 BULK-be39984d
16655 Bulk Product bda6c899 Toys & Games $954.58 280 3.9 16 BULK-b992832f
16656 Bulk Product b32f31be Clothing $317.76 292 3.1 3 BULK-8ad9e440
16657 Bulk Product 33fb7731 Sports & Outdoors $215.03 262 4.1 56 BULK-e72cfc29
16658 Bulk Product 257c7ada Toys & Games $847.25 353 4.5 15 BULK-e6fd1f14
16659 Bulk Product 60d84493 Books $369.68 326 2.8 31 BULK-1a64b9c6
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