Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

9 ms

Page Size

25

Current Page

282 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 282 Results Showing 7026 - 7050 of 24441

ID Name Category Price Stock Rating Reviews SKU
7585 Bulk Product 0cd6d851 Books $394.82 310 3.1 16 BULK-3cf79424
7586 Bulk Product 38f09701 Toys & Games $182.60 470 1.4 29 BULK-a12c3580
7587 Bulk Product ea398550 Clothing $953.35 42 4.9 88 BULK-cdad1a14
7588 Bulk Product 9560355f Electronics $512.26 430 3.0 42 BULK-86d9a25b
7589 Bulk Product ecc17795 Clothing $445.85 38 4.6 84 BULK-1f668483
7590 Bulk Product 2175fc2c Sports & Outdoors $512.73 298 0.5 79 BULK-de57378b
7591 Bulk Product 480b63bd Sports & Outdoors $267.11 330 3.6 95 BULK-0399bb41
7592 Bulk Product d73c9239 Clothing $875.00 77 4.1 57 BULK-8a14b063
7593 Bulk Product 30552286 Books $501.66 33 4.9 48 BULK-42441b7e
7594 Bulk Product d878609a Clothing $785.60 345 3.6 99 BULK-eceb64cf
7595 Bulk Product b7a040b8 Clothing $107.15 143 1.3 24 BULK-a3c13f32
7596 Bulk Product 02725640 Books $743.20 305 4.0 20 BULK-678cedf7
7597 Bulk Product d7ece429 Books $961.41 265 4.7 54 BULK-248f8120
7598 Bulk Product f98f5b61 Toys & Games $356.81 290 1.7 8 BULK-02a5925a
7599 Bulk Product c5fb9c56 Electronics $83.89 333 4.7 66 BULK-5a5da07e
7600 Bulk Product dc9990fc Clothing $590.76 157 1.8 50 BULK-4cc8bb52
7601 Bulk Product 17b6f525 Sports & Outdoors $446.82 364 2.8 43 BULK-8ad1cf54
7602 Bulk Product 4124c12e Books $978.27 463 2.6 3 BULK-7fb71b68
7603 Bulk Product 07e9e890 Toys & Games $818.55 88 4.9 87 BULK-c5b656c6
7604 Bulk Product 1029cdf9 Electronics $714.34 145 0.1 3 BULK-3be2bdcd
7605 Bulk Product 6258754a Electronics $934.77 368 0.8 31 BULK-5ad1b94d
7606 Bulk Product 43983255 Home & Garden $62.48 11 3.9 16 BULK-bec99954
7607 Bulk Product 19f2982d Books $388.89 301 0.5 40 BULK-7b4da032
7608 Bulk Product a1af767a Sports & Outdoors $161.06 257 1.7 50 BULK-1668bb50
7609 Bulk Product e0371cd4 Home & Garden $377.82 56 0.8 38 BULK-33efb414
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