Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

9 ms

Page Size

25

Current Page

72 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 72 Results Showing 1776 - 1800 of 24441

ID Name Category Price Stock Rating Reviews SKU
2006 Standard Electronics Product Mini Electronics $959.69 275 3.2 271 SKU-002006
2007 Pro Office Supplies Product Advanced Office Supplies $447.33 410 4.2 685 SKU-002007
2008 Professional Health & Beauty Product Plus Health & Beauty $13.19 373 2.7 542 SKU-002008
2009 Ultra Toys & Games Product Special Edition Toys & Games $961.72 229 4.6 247 SKU-002009
2010 Mega Clothing Product 2024 Clothing $979.62 341 2.0 714 SKU-002010
2011 Mega Food & Grocery Product XL Food & Grocery $918.27 335 4.3 153 SKU-002011
2012 Elite Toys & Games Product Classic Toys & Games $919.78 14 4.4 232 SKU-002012
2013 Super Food & Grocery Product Special Edition Food & Grocery $65.18 23 3.4 621 SKU-002013
2014 Elite Clothing Product Pro Clothing $175.95 212 2.2 916 SKU-002014
2016 Pro Toys & Games Product Special Edition Toys & Games $322.14 171 1.3 666 SKU-002016
2017 Standard Clothing Product Special Edition Clothing $82.44 136 1.1 932 SKU-002017
2018 Deluxe Health & Beauty Product Pro Health & Beauty $840.46 312 5.0 233 SKU-002018
2019 Pro Food & Grocery Product Advanced Food & Grocery $210.67 201 2.4 593 SKU-002019
2020 Premium Health & Beauty Product 2024 Health & Beauty $828.97 95 4.2 17 SKU-002020
2021 Deluxe Home & Garden Product 2024 Home & Garden $427.87 0 1.9 117 SKU-002021
2022 Mega Home & Garden Product 2024 Home & Garden $942.23 443 4.4 686 SKU-002022
2023 Premium Electronics Product XL Electronics $642.34 230 4.0 252 SKU-002023
2024 Economy Toys & Games Product Advanced Toys & Games $981.32 247 2.0 306 SKU-002024
2025 Pro Food & Grocery Product Special Edition Food & Grocery $149.09 286 3.7 78 SKU-002025
2027 Super Toys & Games Product Pro Toys & Games $549.07 133 2.3 993 SKU-002027
2028 Professional Health & Beauty Product Lite Health & Beauty $280.05 67 3.5 814 SKU-002028
2029 Mega Electronics Product Special Edition Electronics $859.54 485 2.8 546 SKU-002029
2032 Elite Automotive Product Advanced Automotive $755.69 383 2.1 761 SKU-002032
2033 Mega Health & Beauty Product Advanced Health & Beauty $761.92 317 2.7 286 SKU-002033
2034 Pro Toys & Games Product Special Edition Toys & Games $619.09 197 3.2 513 SKU-002034
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