Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

60 ms

Page Size

25

Current Page

280 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 280 Results Showing 6976 - 7000 of 24441

ID Name Category Price Stock Rating Reviews SKU
7535 Bulk Product d15a81ee Toys & Games $608.45 157 3.4 93 BULK-16640d81
7536 Bulk Product 514d38e7 Home & Garden $597.60 238 3.9 46 BULK-12461437
7537 Bulk Product 0fa7a55b Home & Garden $216.03 102 1.3 31 BULK-38ef7d59
7538 Bulk Product 51c8705f Clothing $566.19 427 4.6 67 BULK-ef25a91f
7539 Bulk Product 7c58ba7a Home & Garden $769.31 298 2.4 42 BULK-66ca570a
7540 Bulk Product c8f3c029 Home & Garden $963.62 435 2.0 20 BULK-b044d6ef
7541 Bulk Product b8b88fe7 Books $121.47 204 0.5 43 BULK-4bb252a9
7542 Bulk Product 6eb6ebbe Sports & Outdoors $48.74 165 1.8 79 BULK-ef8154f9
7543 Bulk Product 9d168d80 Home & Garden $449.96 34 1.5 16 BULK-d6b53516
7544 Bulk Product 7089985a Books $763.41 113 3.6 14 BULK-5a90789c
7545 Bulk Product 4573cf09 Toys & Games $367.47 79 0.0 8 BULK-33a51091
7546 Bulk Product 291cb239 Home & Garden $187.83 397 3.9 87 BULK-7da13eb1
7547 Bulk Product 84ff84ab Electronics $507.56 297 0.6 71 BULK-56b1bbee
7548 Bulk Product 5eb69ed9 Books $224.43 11 0.9 92 BULK-4b927883
7549 Bulk Product 68bb5bf7 Sports & Outdoors $968.06 487 3.4 75 BULK-31bf12a1
7550 Bulk Product 8e63aeba Clothing $837.95 153 3.7 91 BULK-20d9db38
7551 Bulk Product be5e4610 Books $92.58 139 4.2 48 BULK-67383c9b
7552 Bulk Product 87064af6 Clothing $911.54 434 1.1 90 BULK-438bb84b
7553 Bulk Product 16d64787 Toys & Games $677.41 471 4.8 20 BULK-56172f66
7554 Bulk Product 4170116e Sports & Outdoors $474.04 299 3.2 91 BULK-1e31af26
7555 Bulk Product 4cba9488 Sports & Outdoors $582.94 36 1.2 12 BULK-7559cddb
7556 Bulk Product f776661d Books $431.14 256 3.4 35 BULK-0ea5aa1a
7557 Bulk Product a0284694 Toys & Games $599.81 421 4.2 16 BULK-948c06ee
7558 Bulk Product d1863edd Books $88.19 442 2.6 84 BULK-8b16ee1b
7559 Bulk Product 4e2b8fed Toys & Games $826.09 383 1.0 41 BULK-1215646c
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