Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

10 ms

Page Size

25

Current Page

359 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 359 Results Showing 8951 - 8975 of 24441

ID Name Category Price Stock Rating Reviews SKU
9510 Bulk Product 2f370073 Sports & Outdoors $858.80 289 1.9 57 BULK-96bd1531
9511 Bulk Product d601de6b Sports & Outdoors $551.25 107 3.9 6 BULK-253c1c53
9512 Bulk Product b1218bba Clothing $923.02 404 1.2 62 BULK-25c5cd27
9513 Bulk Product f06e57bb Books $319.72 479 4.0 49 BULK-cf6e0ec9
9514 Bulk Product 6fc8af93 Sports & Outdoors $866.30 185 0.9 11 BULK-9e2276c6
9515 Bulk Product a3f21f50 Home & Garden $816.81 388 1.6 64 BULK-5583f58b
9516 Bulk Product 762f5331 Clothing $134.61 481 2.9 10 BULK-0292a66e
9517 Bulk Product f66b25ba Toys & Games $488.82 388 3.5 77 BULK-38093f5e
9518 Bulk Product 124d5bd5 Electronics $816.41 32 0.4 45 BULK-8673cdc1
9519 Bulk Product c891c469 Electronics $280.95 131 0.1 30 BULK-ad1cbda0
9520 Bulk Product 312d0349 Books $492.69 142 2.1 95 BULK-e2f6563c
9521 Bulk Product 77167b42 Toys & Games $209.07 416 1.4 82 BULK-04e3b35e
9522 Bulk Product c14a0829 Home & Garden $940.90 336 3.8 30 BULK-8239122b
9523 Bulk Product b685e84e Books $223.06 180 3.5 30 BULK-198bc4c4
9524 Bulk Product 073734e6 Sports & Outdoors $376.39 336 3.4 5 BULK-7ee7da71
9525 Bulk Product 1e2d2fdf Toys & Games $991.24 335 0.9 89 BULK-67417637
9526 Bulk Product f0f03a9a Home & Garden $149.33 495 1.6 58 BULK-18a999d7
9527 Bulk Product af0174dc Electronics $846.43 90 3.9 89 BULK-27823917
9528 Bulk Product 611b0d75 Toys & Games $489.16 342 2.3 66 BULK-3356e694
9529 Bulk Product 080014fd Books $276.06 213 0.3 5 BULK-3527087d
9530 Bulk Product 3bd47a39 Clothing $138.70 120 2.5 25 BULK-e3845444
9531 Bulk Product d6e136a2 Home & Garden $779.63 180 0.5 82 BULK-2b433947
9532 Bulk Product 4f26f26b Home & Garden $328.28 238 4.4 45 BULK-70570a9c
9533 Bulk Product a10623bf Books $78.38 183 0.4 28 BULK-777f91f5
9534 Bulk Product e3ab1177 Books $728.61 424 3.9 16 BULK-3a5f1777
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