Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

46 ms

Page Size

25

Current Page

850 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 850 Results Showing 21226 - 21250 of 24441

ID Name Category Price Stock Rating Reviews SKU
21785 Bulk Product d61d257a Clothing $519.30 343 4.7 82 BULK-749d7ed8
21786 Bulk Product f661a01c Clothing $453.20 478 1.8 83 BULK-42d41f71
21787 Bulk Product 0b650a9e Electronics $451.52 37 2.8 47 BULK-0e0c761a
21788 Bulk Product 75ba10fe Clothing $573.52 377 1.1 2 BULK-d428eabc
21789 Bulk Product ee18e0ff Electronics $280.49 406 2.0 74 BULK-81398f4e
21790 Bulk Product c32661e6 Clothing $354.85 381 0.7 28 BULK-19a51e90
21791 Bulk Product 957f070a Toys & Games $60.11 387 4.4 27 BULK-29cc28b6
21792 Bulk Product 95565fc8 Books $856.73 351 3.3 35 BULK-7d5986b5
21793 Bulk Product d8412f2e Clothing $288.13 451 1.2 32 BULK-e660b08e
21794 Bulk Product 322e80b7 Toys & Games $278.91 355 3.7 91 BULK-64bb6acd
21795 Bulk Product e7b4ddef Electronics $586.72 104 1.3 89 BULK-7f59b2fd
21796 Bulk Product 30b79f03 Electronics $911.33 104 1.3 95 BULK-b637532f
21797 Bulk Product 6489724e Books $308.82 448 1.7 19 BULK-98d97d38
21798 Bulk Product fd180a65 Sports & Outdoors $467.55 155 4.9 24 BULK-5ba8e3cc
21799 Bulk Product bebcea9b Sports & Outdoors $356.07 50 1.7 14 BULK-01eb421e
21800 Bulk Product ecd3b7ce Home & Garden $19.39 216 3.5 38 BULK-3548536b
21801 Bulk Product e63e3656 Clothing $776.14 12 0.2 79 BULK-b65495e8
21802 Bulk Product f951a0df Electronics $111.79 270 4.7 62 BULK-f589a716
21803 Bulk Product 042d79aa Clothing $344.41 109 4.6 74 BULK-e24de9ce
21804 Bulk Product 58315800 Sports & Outdoors $628.21 484 4.9 5 BULK-92720c0f
21805 Bulk Product 7f90f8c0 Electronics $899.98 432 3.9 77 BULK-69c85b40
21806 Bulk Product e63622cf Home & Garden $280.00 257 2.0 92 BULK-b90c8944
21807 Bulk Product a5d5f2f3 Toys & Games $53.41 85 1.5 6 BULK-26eaf396
21808 Bulk Product 61ab36a0 Clothing $79.66 496 2.4 46 BULK-2cc7e1ea
21809 Bulk Product aec63d83 Toys & Games $142.71 477 0.8 46 BULK-79f92080
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