Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

89 ms

Page Size

25

Current Page

299 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 299 Results Showing 7451 - 7475 of 24441

ID Name Category Price Stock Rating Reviews SKU
8010 Bulk Product 61090a5c Home & Garden $416.65 289 2.5 39 BULK-7eb549d6
8011 Bulk Product 4e885d14 Books $50.00 65 0.6 45 BULK-67827457
8012 Bulk Product 77cb79e4 Electronics $384.24 483 3.1 34 BULK-9727c2de
8013 Bulk Product dd09cc88 Home & Garden $740.85 79 2.6 67 BULK-7edfa3e1
8014 Bulk Product 2d117bc8 Electronics $864.77 380 3.5 67 BULK-d880ce23
8015 Bulk Product ad145cbb Home & Garden $416.89 81 2.8 30 BULK-369da9e1
8016 Bulk Product 96a05bc8 Toys & Games $810.45 434 0.2 52 BULK-43c8f30a
8017 Bulk Product 34957880 Books $303.89 330 1.0 98 BULK-7bd244a6
8018 Bulk Product 37e904d0 Toys & Games $208.83 332 4.1 38 BULK-1506dbf9
8019 Bulk Product 3d2a0bd1 Clothing $909.17 235 1.0 45 BULK-f048f7bf
8020 Bulk Product 20698a7e Home & Garden $19.29 454 2.2 18 BULK-39a85da8
8021 Bulk Product 5ce6404f Books $806.16 211 3.8 97 BULK-cc6efa26
8022 Bulk Product e6e00183 Sports & Outdoors $711.78 314 4.9 73 BULK-ba941dc7
8023 Bulk Product 2ec7edf1 Toys & Games $514.42 338 0.6 98 BULK-b0d7b7c3
8024 Bulk Product f21a39af Toys & Games $780.72 113 4.0 66 BULK-507727a6
8025 Bulk Product b34976bc Home & Garden $248.52 77 3.1 77 BULK-e2170fd1
8026 Bulk Product 8d814585 Clothing $958.17 16 4.4 5 BULK-3803330c
8027 Bulk Product 7157bd4d Clothing $924.40 284 4.3 71 BULK-4d4eefab
8028 Bulk Product cb2affb5 Sports & Outdoors $895.96 93 1.0 19 BULK-7ac1a9e2
8029 Bulk Product 1cbcec9e Electronics $733.50 260 3.3 85 BULK-c6275a55
8030 Bulk Product 171a41f7 Toys & Games $151.34 365 1.8 12 BULK-c5ae0102
8031 Bulk Product 99371955 Sports & Outdoors $495.66 128 0.8 32 BULK-a2def690
8032 Bulk Product 1f181de2 Electronics $947.48 350 1.4 47 BULK-f7ccc8a5
8033 Bulk Product 9c3d61a7 Electronics $562.79 475 4.7 64 BULK-6b6b0ebb
8034 Bulk Product 8aafc8bd Home & Garden $907.92 133 4.7 23 BULK-face38e2
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