Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

22 ms

Page Size

25

Current Page

924 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 924 Results Showing 23076 - 23100 of 24441

ID Name Category Price Stock Rating Reviews SKU
23635 Bulk Product b3cfe917 Home & Garden $525.89 320 3.3 35 BULK-e0944143
23636 Bulk Product 470ac8e0 Sports & Outdoors $301.14 127 3.8 10 BULK-ea1bc4c3
23637 Bulk Product 12a42a53 Sports & Outdoors $626.63 276 0.9 19 BULK-649a4439
23638 Bulk Product 6473dd03 Clothing $680.13 185 4.3 94 BULK-cce8e220
23639 Bulk Product daa03ce9 Electronics $833.77 217 4.3 26 BULK-b3f580c2
23640 Bulk Product 0bf3076f Sports & Outdoors $476.75 332 2.2 38 BULK-f7c2bce5
23641 Bulk Product 9f9acb27 Toys & Games $33.28 423 1.2 93 BULK-f5e229b0
23642 Bulk Product 1f3703d5 Home & Garden $744.38 493 1.1 80 BULK-5b06acca
23643 Bulk Product 896541e0 Toys & Games $332.30 101 5.0 5 BULK-c93f584a
23644 Bulk Product e3003398 Clothing $151.79 185 2.7 44 BULK-63c442ea
23645 Bulk Product b9bb3936 Toys & Games $935.20 197 4.1 1 BULK-ed8210a7
23646 Bulk Product a4e1a219 Clothing $811.71 472 3.3 14 BULK-a3eca7c4
23647 Bulk Product e48ce17a Books $722.90 443 1.8 63 BULK-f887d677
23648 Bulk Product d7f85676 Books $637.56 487 1.0 81 BULK-928292ed
23649 Bulk Product 48a6fe5d Home & Garden $523.61 118 4.3 39 BULK-86e33b89
23650 Bulk Product 5c2ad949 Home & Garden $886.47 54 4.8 51 BULK-e5d24bba
23651 Bulk Product 0662f528 Sports & Outdoors $484.97 227 0.7 26 BULK-f5de9689
23652 Bulk Product 010b79f5 Clothing $564.40 87 2.8 47 BULK-44d016c6
23653 Bulk Product 2e90acb9 Books $902.87 110 4.8 96 BULK-958ad1d3
23654 Bulk Product ac000188 Toys & Games $169.99 15 0.4 54 BULK-72a19bc1
23655 Bulk Product fd3e4df3 Toys & Games $809.81 190 2.5 72 BULK-086069ba
23656 Bulk Product d45440ef Home & Garden $778.27 261 2.6 21 BULK-bcbf86b1
23657 Bulk Product e932eb30 Home & Garden $561.84 420 4.5 98 BULK-9a33c659
23658 Bulk Product 3bd1d413 Toys & Games $303.34 258 4.6 53 BULK-4813b21e
23659 Bulk Product 0b63fffc Toys & Games $153.86 192 3.8 52 BULK-f62ba1cd
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