Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

12 ms

Page Size

25

Current Page

398 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 398 Results Showing 9926 - 9950 of 24441

ID Name Category Price Stock Rating Reviews SKU
10485 Bulk Product dab1e557 Sports & Outdoors $928.15 94 0.4 58 BULK-506f22d3
10486 Bulk Product d6766ed8 Sports & Outdoors $985.24 463 3.1 54 BULK-83e0d44f
10487 Bulk Product c7e46cb3 Home & Garden $337.20 464 1.8 70 BULK-05d2227d
10488 Bulk Product 56601995 Electronics $179.90 246 1.4 57 BULK-f39a8994
10489 Bulk Product 5224dac4 Sports & Outdoors $821.32 8 1.2 6 BULK-ff39ddfb
10490 Bulk Product 7ab71023 Sports & Outdoors $150.52 489 0.7 93 BULK-8c44e4df
10491 Bulk Product eb3e15ce Books $602.71 451 0.1 48 BULK-200e8c08
10492 Bulk Product 63e72787 Clothing $52.57 48 2.3 84 BULK-5e355fde
10493 Bulk Product 9b483eca Sports & Outdoors $323.55 489 1.7 83 BULK-61ecc65f
10494 Bulk Product ff8634e7 Clothing $656.45 203 3.3 97 BULK-1d69d899
10495 Bulk Product a989e3fa Home & Garden $607.61 72 1.8 80 BULK-fa7d517e
10496 Bulk Product a7fccd13 Home & Garden $890.65 67 3.0 37 BULK-acbe9d68
10497 Bulk Product 001de619 Sports & Outdoors $633.88 199 3.4 47 BULK-a68c8f5a
10498 Bulk Product 74690e03 Clothing $783.23 41 3.5 22 BULK-d95031ed
10499 Bulk Product dc95a9fe Sports & Outdoors $791.39 486 0.6 46 BULK-b0ccf033
10500 Bulk Product b5149614 Electronics $31.51 327 2.7 75 BULK-b7e9a233
10501 Bulk Product 700e7f6c Home & Garden $1,006.74 98 1.0 80 BULK-a4a7e9ba
10502 Bulk Product 614b6750 Toys & Games $876.30 439 1.0 13 BULK-ec6dd410
10503 Bulk Product c8523278 Home & Garden $812.47 373 4.2 97 BULK-f86d1723
10504 Bulk Product 13f00113 Clothing $856.57 445 1.5 50 BULK-0ddbde1a
10505 Bulk Product 2f967b7a Sports & Outdoors $533.68 336 1.6 14 BULK-801b9313
10506 Bulk Product 0cb9acb4 Home & Garden $597.07 135 2.3 64 BULK-f4459557
10507 Bulk Product 9c8a71f1 Toys & Games $695.17 409 3.9 22 BULK-76255acd
10508 Bulk Product 507205f0 Electronics $919.58 18 3.6 94 BULK-b47f5152
10509 Bulk Product f706c08b Toys & Games $843.98 306 4.1 59 BULK-9ac09d70
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