Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

35 ms

Page Size

25

Current Page

139 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 139 Results Showing 3451 - 3475 of 24441

ID Name Category Price Stock Rating Reviews SKU
3874 Deluxe Health & Beauty Product Max Health & Beauty $906.88 431 4.0 623 SKU-003874
3875 Pro Sports & Outdoors Product Max Sports & Outdoors $608.02 443 4.7 237 SKU-003875
3876 Super Books Product XL Books $919.63 2 3.9 475 SKU-003876
3877 Ultra Books Product Mini Books $371.34 404 3.4 316 SKU-003877
3878 Ultra Sports & Outdoors Product 2024 Sports & Outdoors $702.57 280 3.6 354 SKU-003878
3879 Economy Electronics Product Plus Electronics $74.06 76 1.2 721 SKU-003879
3880 Deluxe Toys & Games Product Plus Toys & Games $491.52 117 1.6 987 SKU-003880
3883 Super Electronics Product Advanced Electronics $401.03 122 2.0 378 SKU-003883
3884 Economy Food & Grocery Product Pro Food & Grocery $493.38 38 1.3 33 SKU-003884
3885 Mega Toys & Games Product Pro Toys & Games $305.11 208 1.4 493 SKU-003885
3886 Professional Food & Grocery Product 2024 Food & Grocery $829.90 100 2.0 470 SKU-003886
3889 Elite Sports & Outdoors Product Lite Sports & Outdoors $722.11 8 1.6 735 SKU-003889
3891 Economy Food & Grocery Product Plus Food & Grocery $764.87 45 2.9 702 SKU-003891
3892 Super Toys & Games Product Classic Toys & Games $128.32 379 4.0 200 SKU-003892
3893 Elite Automotive Product Special Edition Automotive $96.86 133 1.5 180 SKU-003893
3894 Standard Clothing Product Special Edition Clothing $818.60 316 2.0 864 SKU-003894
3895 Standard Sports & Outdoors Product Classic Sports & Outdoors $592.71 141 2.8 345 SKU-003895
3896 Professional Clothing Product Lite Clothing $900.83 273 3.5 694 SKU-003896
3897 Ultra Sports & Outdoors Product Classic Sports & Outdoors $308.15 287 2.8 526 SKU-003897
3898 Ultra Sports & Outdoors Product 2024 Sports & Outdoors $301.64 22 4.2 491 SKU-003898
3899 Deluxe Sports & Outdoors Product 2024 Sports & Outdoors $948.34 117 3.8 919 SKU-003899
3900 Pro Food & Grocery Product Pro Food & Grocery $457.60 411 3.3 366 SKU-003900
3901 Economy Toys & Games Product Classic Toys & Games $459.01 355 2.6 816 SKU-003901
3903 Pro Office Supplies Product Pro Office Supplies $14.91 154 4.9 178 SKU-003903
3904 Pro Clothing Product Pro Clothing $357.61 75 4.4 272 SKU-003904
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