Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

14 ms

Page Size

25

Current Page

903 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 903 Results Showing 22551 - 22575 of 24441

ID Name Category Price Stock Rating Reviews SKU
23110 Bulk Product 73ce76ca Electronics $490.03 482 2.6 6 BULK-37ec2e74
23111 Bulk Product ab44f3e6 Toys & Games $504.13 276 1.9 97 BULK-cf909e08
23112 Bulk Product d6d3c198 Sports & Outdoors $880.70 98 3.0 28 BULK-156d984c
23113 Bulk Product b9e54415 Books $126.50 112 1.7 76 BULK-7ed4de83
23114 Bulk Product 545ca592 Toys & Games $453.69 181 4.6 26 BULK-de55a12e
23115 Bulk Product 0c152c01 Clothing $775.64 103 1.6 77 BULK-92657719
23116 Bulk Product fcdbb290 Clothing $223.16 317 1.9 44 BULK-eff03a86
23117 Bulk Product f719f8fe Home & Garden $999.05 226 2.8 35 BULK-b114b946
23118 Bulk Product 138749a3 Clothing $658.83 433 1.3 10 BULK-b8b081a1
23119 Bulk Product 9a62c391 Electronics $703.94 295 0.3 77 BULK-508186db
23120 Bulk Product 8c5af2c3 Clothing $527.20 9 3.6 17 BULK-4d2cb9c7
23121 Bulk Product 88e98c51 Home & Garden $227.22 382 2.0 23 BULK-69d6e0b1
23122 Bulk Product f8008a4a Clothing $825.44 316 4.0 10 BULK-879c2a95
23123 Bulk Product 5326b560 Books $725.08 407 0.6 58 BULK-fd74a260
23124 Bulk Product 5ace989a Clothing $697.77 258 3.1 39 BULK-1732a6c6
23125 Bulk Product 5cec10db Toys & Games $479.39 346 1.0 43 BULK-c282dba3
23126 Bulk Product 8de0fb36 Electronics $846.84 426 1.3 32 BULK-28d387fe
23127 Bulk Product 30a493ec Electronics $212.39 170 4.5 28 BULK-2205d966
23128 Bulk Product fa22dda2 Books $351.66 198 4.3 94 BULK-f20a40df
23129 Bulk Product 8e873dcd Sports & Outdoors $619.56 59 4.8 32 BULK-0701269d
23130 Bulk Product 8668ae52 Home & Garden $200.94 464 0.9 2 BULK-f07cf071
23131 Bulk Product 0e2b6226 Clothing $489.04 243 2.0 50 BULK-5e93c7d1
23132 Bulk Product 6c138e33 Books $383.43 337 4.0 75 BULK-61ef2e7e
23133 Bulk Product d5510403 Books $72.99 118 2.2 61 BULK-c7396c42
23134 Bulk Product 3dd98267 Electronics $430.68 281 4.7 92 BULK-06bc386d
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