Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

26 ms

Page Size

25

Current Page

757 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 757 Results Showing 18901 - 18925 of 24441

ID Name Category Price Stock Rating Reviews SKU
19460 Bulk Product df494cbd Home & Garden $90.84 94 0.8 86 BULK-847a881b
19461 Bulk Product fbf6616d Sports & Outdoors $485.97 483 1.7 16 BULK-c15d7882
19462 Bulk Product 5915b552 Electronics $969.57 182 2.9 70 BULK-ec603ca3
19463 Bulk Product a49fa8fc Electronics $948.69 404 3.1 65 BULK-00050ce1
19464 Bulk Product 4d6d3e81 Clothing $48.24 264 3.0 20 BULK-4d7563bc
19465 Bulk Product 17416ca5 Books $915.99 367 2.9 47 BULK-b23bcd25
19466 Bulk Product 42d3b802 Sports & Outdoors $683.86 331 2.2 6 BULK-b1c0a9c9
19467 Bulk Product 080693a1 Sports & Outdoors $466.25 412 3.2 72 BULK-cdf5186f
19468 Bulk Product fb1745da Toys & Games $884.29 480 0.5 51 BULK-a0a0544e
19469 Bulk Product 76d9eea6 Electronics $376.86 176 3.0 9 BULK-a9dfc182
19470 Bulk Product 7494c299 Sports & Outdoors $918.66 451 2.3 77 BULK-a27f5b48
19471 Bulk Product 705fe857 Toys & Games $189.53 278 3.9 13 BULK-16f66ce5
19472 Bulk Product 102ff892 Books $561.41 143 2.1 56 BULK-c009147b
19473 Bulk Product 63a986c9 Toys & Games $440.03 150 2.1 42 BULK-b67c3121
19474 Bulk Product 8d81ce0d Electronics $393.92 99 2.3 30 BULK-42222e10
19475 Bulk Product 801448de Sports & Outdoors $699.39 106 3.5 76 BULK-dda85d22
19476 Bulk Product 84b45665 Books $40.53 491 1.4 64 BULK-0e115454
19477 Bulk Product b96d1190 Sports & Outdoors $46.09 172 0.1 1 BULK-4ddff0d6
19478 Bulk Product 1e07cf4b Clothing $772.78 341 2.6 94 BULK-c423d3af
19479 Bulk Product 595bbc0d Electronics $301.11 273 2.1 31 BULK-60270c47
19480 Bulk Product e2fde15b Electronics $813.43 479 1.5 72 BULK-ad34d6df
19481 Bulk Product 28ac83f1 Clothing $15.18 1 4.6 9 BULK-108cd988
19482 Bulk Product a4ffd9d7 Home & Garden $565.65 44 2.0 2 BULK-ce0294c3
19483 Bulk Product 19e1122d Home & Garden $663.18 80 3.2 7 BULK-9aa4e813
19484 Bulk Product 5a88aca9 Toys & Games $494.93 35 0.9 64 BULK-73c599da
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