Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

46 ms

Page Size

50

Current Page

34 / 489

Total Records

24441

Items per page: 25 50 100 200

Page 34 Results Showing 1651 - 1700 of 24441

ID Name Category Price Stock Rating Reviews SKU
1865 Mega Electronics Product Mini Electronics $286.40 465 3.4 591 SKU-001865
1866 Professional Clothing Product Advanced Clothing $464.23 49 4.5 642 SKU-001866
1867 Standard Food & Grocery Product 2024 Food & Grocery $132.84 352 1.1 739 SKU-001867
1868 Standard Office Supplies Product Classic Office Supplies $508.29 309 1.6 68 SKU-001868
1869 Economy Automotive Product Max Automotive $859.60 135 1.2 61 SKU-001869
1870 Super Toys & Games Product Max Toys & Games $857.96 337 3.1 399 SKU-001870
1871 Economy Clothing Product Special Edition Clothing $874.61 78 2.1 587 SKU-001871
1873 Premium Clothing Product Max Clothing $522.81 300 4.4 864 SKU-001873
1874 Economy Office Supplies Product Special Edition Office Supplies $46.09 16 2.5 775 SKU-001874
1875 Premium Home & Garden Product XL Home & Garden $900.13 51 1.2 611 SKU-001875
1876 Premium Health & Beauty Product Classic Health & Beauty $269.65 330 4.9 207 SKU-001876
1878 Deluxe Health & Beauty Product Pro Health & Beauty $385.11 388 2.2 420 SKU-001878
1879 Standard Toys & Games Product XL Toys & Games $810.73 25 1.5 827 SKU-001879
1880 Pro Automotive Product 2024 Automotive $921.95 397 1.6 7 SKU-001880
1881 Elite Electronics Product XL Electronics $743.37 225 4.1 337 SKU-001881
1882 Elite Health & Beauty Product Max Health & Beauty $577.11 368 2.1 903 SKU-001882
1883 Deluxe Home & Garden Product Plus Home & Garden $463.14 350 1.8 153 SKU-001883
1884 Premium Health & Beauty Product Pro Health & Beauty $914.88 160 3.0 228 SKU-001884
1885 Standard Sports & Outdoors Product Max Sports & Outdoors $495.82 491 2.2 631 SKU-001885
1886 Standard Health & Beauty Product Classic Health & Beauty $679.29 420 1.6 675 SKU-001886
1887 Deluxe Health & Beauty Product XL Health & Beauty $992.16 207 1.6 515 SKU-001887
1888 Premium Food & Grocery Product Mini Food & Grocery $952.85 122 2.9 605 SKU-001888
1889 Super Books Product Special Edition Books $724.75 491 3.4 775 SKU-001889
1890 Deluxe Clothing Product 2024 Clothing $840.67 373 1.1 334 SKU-001890
1891 Super Food & Grocery Product Plus Food & Grocery $573.89 11 2.8 565 SKU-001891
1892 Deluxe Food & Grocery Product Max Food & Grocery $104.70 494 4.2 646 SKU-001892
1893 Professional Automotive Product Classic Automotive $623.44 314 1.5 432 SKU-001893
1894 Super Office Supplies Product Advanced Office Supplies $307.11 325 1.6 0 SKU-001894
1895 Deluxe Toys & Games Product Special Edition Toys & Games $505.15 451 1.3 617 SKU-001895
1897 Super Health & Beauty Product Mini Health & Beauty $467.78 55 3.1 123 SKU-001897
1898 Standard Office Supplies Product Classic Office Supplies $507.10 26 3.8 700 SKU-001898
1899 Elite Sports & Outdoors Product Lite Sports & Outdoors $701.19 412 2.5 255 SKU-001899
1900 Super Automotive Product Special Edition Automotive $47.84 178 1.7 67 SKU-001900
1901 Ultra Sports & Outdoors Product 2024 Sports & Outdoors $525.42 481 2.6 168 SKU-001901
1904 Premium Health & Beauty Product Plus Health & Beauty $171.85 27 1.0 504 SKU-001904
1905 Premium Electronics Product Special Edition Electronics $523.36 126 1.5 303 SKU-001905
1906 Mega Office Supplies Product Advanced Office Supplies $142.71 285 3.2 448 SKU-001906
1907 Ultra Health & Beauty Product Lite Health & Beauty $854.68 244 3.4 415 SKU-001907
1908 Ultra Food & Grocery Product Max Food & Grocery $268.72 99 2.3 86 SKU-001908
1909 Premium Automotive Product Mini Automotive $455.98 22 3.0 334 SKU-001909
1912 Economy Clothing Product Advanced Clothing $981.45 129 5.0 847 SKU-001912
1913 Elite Food & Grocery Product Pro Food & Grocery $696.96 147 1.8 604 SKU-001913
1914 Ultra Electronics Product Special Edition Electronics $581.44 208 2.9 243 SKU-001914
1915 Pro Food & Grocery Product Lite Food & Grocery $602.14 62 1.2 696 SKU-001915
1916 Professional Electronics Product 2024 Electronics $437.76 405 1.6 786 SKU-001916
1917 Super Sports & Outdoors Product Mini Sports & Outdoors $243.34 377 4.4 854 SKU-001917
1918 Deluxe Toys & Games Product 2024 Toys & Games $613.90 288 3.0 341 SKU-001918
1919 Standard Clothing Product 2024 Clothing $246.39 17 4.0 959 SKU-001919
1920 Super Books Product Special Edition Books $420.49 479 1.2 383 SKU-001920
1922 Super Electronics Product 2024 Electronics $418.32 483 2.9 61 SKU-001922
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