Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

36 ms

Page Size

25

Current Page

71 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 71 Results Showing 1751 - 1775 of 24441

ID Name Category Price Stock Rating Reviews SKU
1979 Pro Automotive Product Mini Automotive $144.65 37 2.5 562 SKU-001979
1980 Economy Health & Beauty Product Advanced Health & Beauty $743.67 376 3.8 899 SKU-001980
1981 Standard Books Product Mini Books $900.60 426 3.2 395 SKU-001981
1982 Professional Food & Grocery Product Classic Food & Grocery $405.35 219 3.8 878 SKU-001982
1983 Super Office Supplies Product XL Office Supplies $22.74 215 2.6 983 SKU-001983
1984 Deluxe Sports & Outdoors Product Advanced Sports & Outdoors $945.84 229 3.6 567 SKU-001984
1985 Mega Sports & Outdoors Product Max Sports & Outdoors $427.54 291 1.6 479 SKU-001985
1986 Professional Office Supplies Product Special Edition Office Supplies $314.96 150 2.4 743 SKU-001986
1987 Mega Electronics Product 2024 Electronics $609.06 269 4.6 252 SKU-001987
1988 Professional Sports & Outdoors Product 2024 Sports & Outdoors $475.69 184 4.1 307 SKU-001988
1989 Deluxe Office Supplies Product Pro Office Supplies $75.37 418 3.7 502 SKU-001989
1990 Professional Toys & Games Product XL Toys & Games $306.30 98 2.8 560 SKU-001990
1991 Standard Home & Garden Product Classic Home & Garden $37.20 210 3.4 947 SKU-001991
1992 Ultra Books Product 2024 Books $627.40 481 3.0 522 SKU-001992
1995 Deluxe Automotive Product Pro Automotive $700.98 108 3.9 873 SKU-001995
1996 Super Clothing Product Advanced Clothing $918.63 99 1.6 863 SKU-001996
1997 Mega Automotive Product Advanced Automotive $209.82 207 3.7 889 SKU-001997
1998 Deluxe Sports & Outdoors Product Mini Sports & Outdoors $833.19 43 1.6 467 SKU-001998
1999 Super Electronics Product Plus Electronics $625.95 448 2.0 181 SKU-001999
2000 Elite Food & Grocery Product Advanced Food & Grocery $570.58 411 2.5 117 SKU-002000
2001 Economy Toys & Games Product Mini Toys & Games $284.69 55 1.5 846 SKU-002001
2002 Pro Health & Beauty Product Plus Health & Beauty $522.69 460 4.5 394 SKU-002002
2003 Ultra Home & Garden Product Classic Home & Garden $191.40 333 3.3 88 SKU-002003
2004 Pro Books Product Mini Books $600.71 176 1.7 142 SKU-002004
2005 Elite Electronics Product Lite Electronics $208.66 332 1.4 385 SKU-002005
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