Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

39 ms

Page Size

25

Current Page

832 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 832 Results Showing 20776 - 20800 of 24441

ID Name Category Price Stock Rating Reviews SKU
21335 Bulk Product 4a7435d6 Toys & Games $334.31 423 0.0 80 BULK-d0d5ec79
21336 Bulk Product 82debedc Books $442.71 40 4.2 85 BULK-f2004a89
21337 Bulk Product 44633075 Sports & Outdoors $218.80 0 1.6 23 BULK-a56add78
21338 Bulk Product 0a0cfdab Toys & Games $896.28 178 3.5 66 BULK-2c8b6cd6
21339 Bulk Product d464e0cb Home & Garden $850.61 408 4.4 51 BULK-0b26daea
21340 Bulk Product eeac50a4 Clothing $635.28 468 2.1 40 BULK-77c2d6af
21341 Bulk Product 03a1cff6 Home & Garden $403.62 264 1.1 65 BULK-a2f578a4
21342 Bulk Product 58cccdd0 Clothing $346.46 192 3.3 41 BULK-cea4a9de
21343 Bulk Product fc2fa900 Home & Garden $957.00 219 3.7 49 BULK-4c5c3ac7
21344 Bulk Product 9ef779d5 Books $961.52 219 0.2 30 BULK-3bb6f4d2
21345 Bulk Product 7778876c Toys & Games $361.30 293 4.6 82 BULK-6310f329
21346 Bulk Product 534ae3ca Home & Garden $394.85 99 1.0 84 BULK-ad8897d3
21347 Bulk Product 6eef0972 Clothing $923.85 29 4.0 96 BULK-1b37f381
21348 Bulk Product 4fd16dcf Home & Garden $756.28 409 1.3 63 BULK-6e4048e8
21349 Bulk Product e6ab774a Clothing $518.84 148 4.5 14 BULK-67325066
21350 Bulk Product fc7a1748 Electronics $97.97 481 4.3 92 BULK-334b42fe
21351 Bulk Product 54ae015d Books $76.12 374 3.3 41 BULK-1afd9ed4
21352 Bulk Product d0f9b731 Toys & Games $137.29 222 0.6 46 BULK-196a3ddd
21353 Bulk Product 82289373 Electronics $933.68 329 3.5 18 BULK-86fa1b7a
21354 Bulk Product 546f16ea Toys & Games $263.39 83 0.8 81 BULK-8c767dd2
21355 Bulk Product 6065ac58 Home & Garden $146.82 336 2.8 30 BULK-d6183bf9
21356 Bulk Product a569d580 Home & Garden $847.82 476 0.1 67 BULK-669dc52d
21357 Bulk Product 2981cd23 Toys & Games $85.34 134 3.0 52 BULK-bbc2c291
21358 Bulk Product 6696cc3c Electronics $143.14 69 3.9 98 BULK-3c87bbf4
21359 Bulk Product 1af71997 Sports & Outdoors $746.26 407 3.3 57 BULK-d183b26a
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