Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

20 ms

Page Size

25

Current Page

564 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 564 Results Showing 14076 - 14100 of 24441

ID Name Category Price Stock Rating Reviews SKU
14635 Bulk Product 68e41511 Books $102.99 98 1.5 84 BULK-821b2980
14636 Bulk Product ffffe821 Clothing $441.02 386 3.1 89 BULK-0d6106b9
14637 Bulk Product 7be380fa Electronics $462.49 315 3.4 0 BULK-1aeefd73
14638 Bulk Product c3c8658c Electronics $582.39 389 1.2 2 BULK-9b465ab3
14639 Bulk Product 3c42268e Home & Garden $391.75 279 1.6 63 BULK-c4cb5b26
14640 Bulk Product 3307a67f Books $55.51 217 0.8 56 BULK-3518d2fc
14641 Bulk Product de6a444e Toys & Games $359.49 269 1.6 23 BULK-89e1b05e
14642 Bulk Product 5223aecc Toys & Games $906.38 433 1.6 45 BULK-3378f3b4
14643 Bulk Product 1f4b0a16 Clothing $677.83 243 3.6 31 BULK-a59e8fc2
14644 Bulk Product 26ead5ef Sports & Outdoors $875.33 320 3.0 77 BULK-65a8944d
14645 Bulk Product 9882af8d Home & Garden $257.91 384 1.0 81 BULK-56e0f1d6
14646 Bulk Product 0e971e93 Books $948.44 212 3.2 75 BULK-e66d95c2
14647 Bulk Product c951481b Books $37.39 491 5.0 49 BULK-4805f080
14648 Bulk Product 90a6b065 Home & Garden $846.07 88 0.3 84 BULK-a9e015c0
14649 Bulk Product a593fe4e Books $562.14 482 4.8 84 BULK-86501c4c
14650 Bulk Product a6c25a40 Toys & Games $199.29 178 2.5 99 BULK-b4d7b1bc
14651 Bulk Product 44fa0d1c Books $760.65 479 4.8 55 BULK-a16413c2
14652 Bulk Product 526c42e8 Toys & Games $582.21 392 1.3 44 BULK-b95273ba
14653 Bulk Product 0b12c0e9 Clothing $840.90 77 2.8 35 BULK-8d2bf0b6
14654 Bulk Product 5dca3e42 Home & Garden $336.54 382 0.9 22 BULK-61b13fec
14655 Bulk Product 1cd5275c Books $103.80 448 2.8 53 BULK-9e18c110
14656 Bulk Product 9fffe3c0 Clothing $394.56 405 0.2 20 BULK-e2afbf38
14657 Bulk Product c4b75329 Toys & Games $886.28 317 4.2 17 BULK-57e551a3
14658 Bulk Product 1716d040 Sports & Outdoors $404.97 282 3.6 69 BULK-b1e052bd
14659 Bulk Product d67d977b Clothing $717.13 380 1.3 44 BULK-3d56f307
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