Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

1726 ms

Page Size

25

Current Page

328 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 328 Results Showing 8176 - 8200 of 24441

ID Name Category Price Stock Rating Reviews SKU
8735 Bulk Product 3e7ade30 Toys & Games $964.33 83 2.3 22 BULK-6c074df4
8736 Bulk Product 38787c68 Home & Garden $967.40 0 3.3 72 BULK-db249f2d
8737 Bulk Product 6ee7fb2d Home & Garden $605.08 302 0.7 12 BULK-2c313e59
8738 Bulk Product 519faefd Clothing $638.39 81 4.1 14 BULK-03bc2707
8739 Bulk Product 6615c61c Toys & Games $419.46 310 0.6 18 BULK-565372be
8740 Bulk Product 879d71f5 Sports & Outdoors $648.17 487 4.0 38 BULK-61263384
8741 Bulk Product 39bea089 Electronics $838.19 97 1.1 83 BULK-453ea0ef
8742 Bulk Product 9e50d630 Clothing $686.46 147 2.4 98 BULK-0d7ac79e
8743 Bulk Product 959ab3ca Sports & Outdoors $921.69 21 4.6 62 BULK-b9ae55cd
8744 Bulk Product f4fe0f63 Sports & Outdoors $160.78 186 3.9 26 BULK-614a8299
8745 Bulk Product e1e36ca2 Clothing $272.10 403 4.6 23 BULK-811c8a30
8746 Bulk Product 1f4f6065 Clothing $716.46 211 4.0 6 BULK-6d990bb3
8747 Bulk Product 26ac63fc Home & Garden $338.22 108 1.5 63 BULK-f07a9db7
8748 Bulk Product 6bd3daae Clothing $673.59 498 0.8 32 BULK-04d0589b
8749 Bulk Product f231dd13 Toys & Games $92.10 60 3.7 7 BULK-1710eb1d
8750 Bulk Product b860f81b Electronics $703.94 189 3.3 28 BULK-618b9e62
8751 Bulk Product 7ad0300b Home & Garden $314.74 298 2.5 43 BULK-ef6881a7
8752 Bulk Product 74f1a08d Electronics $701.90 487 3.1 24 BULK-7a6da03c
8753 Bulk Product 0cb71727 Books $70.96 222 3.9 25 BULK-3794d509
8754 Bulk Product a79ce942 Clothing $736.19 45 3.4 73 BULK-a2b492b5
8755 Bulk Product d6c90447 Toys & Games $634.74 127 3.2 59 BULK-2da04dce
8756 Bulk Product f83d88e2 Books $46.18 96 4.3 70 BULK-30b74754
8757 Bulk Product 1671a52a Electronics $170.43 258 0.3 93 BULK-6a28f544
8758 Bulk Product 8cddd120 Books $890.72 381 4.3 83 BULK-92ec91ee
8759 Bulk Product 9ffdfe06 Electronics $160.19 130 4.8 70 BULK-804e8663
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