Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

45 ms

Page Size

25

Current Page

524 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 524 Results Showing 13076 - 13100 of 24441

ID Name Category Price Stock Rating Reviews SKU
13635 Bulk Product 936b8927 Toys & Games $489.14 235 2.6 74 BULK-314079f4
13636 Bulk Product 0b86cadc Toys & Games $790.74 416 3.5 14 BULK-afe87a00
13637 Bulk Product 621624a2 Home & Garden $959.73 428 4.7 94 BULK-b4367baf
13638 Bulk Product 0e3e4602 Books $904.28 126 1.7 59 BULK-cef76fc4
13639 Bulk Product 145dd2d8 Books $335.61 395 2.1 52 BULK-78043867
13640 Bulk Product af243877 Electronics $928.36 150 2.6 3 BULK-6a4b5fe8
13641 Bulk Product 344c7613 Sports & Outdoors $328.73 364 0.5 46 BULK-c76d1896
13642 Bulk Product 74d39535 Electronics $662.39 240 3.8 30 BULK-2b9abe44
13643 Bulk Product 31dec56c Toys & Games $42.47 156 2.1 90 BULK-56e709e3
13644 Bulk Product 6c27f5c1 Electronics $904.11 384 4.5 89 BULK-24813b8e
13645 Bulk Product 0380c466 Books $251.72 376 3.4 87 BULK-76ff83f5
13646 Bulk Product b5f5b981 Toys & Games $494.77 309 1.4 31 BULK-5e2bb279
13647 Bulk Product 12596a37 Sports & Outdoors $801.51 130 2.4 96 BULK-7df4276c
13648 Bulk Product 19814d97 Clothing $34.53 167 4.6 22 BULK-ac496389
13649 Bulk Product bf69d92a Home & Garden $443.02 457 4.3 57 BULK-b8138322
13650 Bulk Product 7ab8ef53 Electronics $374.16 229 3.2 42 BULK-f3b99f85
13651 Bulk Product 93409f55 Books $429.28 363 1.2 80 BULK-668687cc
13652 Bulk Product 35561690 Home & Garden $929.87 443 5.0 60 BULK-302be892
13653 Bulk Product a0985cb0 Electronics $617.71 128 4.3 98 BULK-c66f302d
13654 Bulk Product f9037fec Sports & Outdoors $449.05 408 5.0 26 BULK-64b03b9c
13655 Bulk Product 097cde8f Home & Garden $245.80 190 0.2 21 BULK-c9a1b18f
13656 Bulk Product ee78762c Home & Garden $853.14 336 3.1 38 BULK-d23cd1bd
13657 Bulk Product ad4ae81f Books $719.09 465 4.8 84 BULK-7e8f149a
13658 Bulk Product b32ac9d8 Clothing $1,002.24 370 3.7 11 BULK-f90ce6d6
13659 Bulk Product 693430da Books $509.08 24 2.3 63 BULK-3ec24e68
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