Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

18 ms

Page Size

25

Current Page

143 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 143 Results Showing 3551 - 3575 of 24441

ID Name Category Price Stock Rating Reviews SKU
3986 Premium Automotive Product Max Automotive $555.69 348 1.3 43 SKU-003986
3987 Mega Electronics Product Special Edition Electronics $965.03 482 1.9 597 SKU-003987
3988 Ultra Automotive Product Advanced Automotive $63.41 187 4.0 150 SKU-003988
3989 Economy Health & Beauty Product XL Health & Beauty $922.33 180 2.8 272 SKU-003989
3990 Ultra Home & Garden Product Plus Home & Garden $580.79 10 1.5 237 SKU-003990
3991 Super Food & Grocery Product XL Food & Grocery $343.81 471 1.4 588 SKU-003991
3992 Super Automotive Product 2024 Automotive $933.28 238 2.1 704 SKU-003992
3993 Ultra Health & Beauty Product Special Edition Health & Beauty $149.34 375 4.5 34 SKU-003993
3994 Elite Home & Garden Product Max Home & Garden $733.19 335 2.6 657 SKU-003994
3995 Super Electronics Product Advanced Electronics $963.99 416 3.8 428 SKU-003995
3996 Premium Toys & Games Product Classic Toys & Games $52.58 19 4.9 524 SKU-003996
3997 Professional Automotive Product 2024 Automotive $249.42 15 3.5 236 SKU-003997
4000 Ultra Sports & Outdoors Product 2024 Sports & Outdoors $471.16 71 4.0 963 SKU-004000
4001 Elite Health & Beauty Product Special Edition Health & Beauty $167.98 222 3.5 423 SKU-004001
4003 Super Home & Garden Product Advanced Home & Garden $739.74 56 1.3 448 SKU-004003
4004 Ultra Food & Grocery Product XL Food & Grocery $924.59 354 1.9 671 SKU-004004
4005 Pro Home & Garden Product XL Home & Garden $278.87 84 5.0 74 SKU-004005
4006 Mega Home & Garden Product Special Edition Home & Garden $793.73 102 3.9 903 SKU-004006
4007 Mega Food & Grocery Product XL Food & Grocery $435.27 183 3.7 888 SKU-004007
4008 Economy Clothing Product 2024 Clothing $571.51 164 4.1 742 SKU-004008
4009 Mega Clothing Product Special Edition Clothing $750.28 36 4.4 581 SKU-004009
4010 Mega Automotive Product Lite Automotive $820.89 346 3.2 286 SKU-004010
4011 Deluxe Sports & Outdoors Product Lite Sports & Outdoors $673.67 131 5.0 898 SKU-004011
4012 Elite Home & Garden Product Mini Home & Garden $775.05 299 3.6 377 SKU-004012
4013 Standard Office Supplies Product Lite Office Supplies $619.22 327 4.5 628 SKU-004013
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