Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

26 ms

Page Size

25

Current Page

805 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 805 Results Showing 20101 - 20125 of 24441

ID Name Category Price Stock Rating Reviews SKU
20660 Bulk Product db4ce276 Toys & Games $375.60 379 0.3 96 BULK-0b315dfc
20661 Bulk Product a9874fa3 Sports & Outdoors $241.84 93 2.4 73 BULK-b17c337a
20662 Bulk Product 98e529f5 Sports & Outdoors $920.23 435 1.7 21 BULK-8f074cff
20663 Bulk Product 2cf924e0 Books $479.17 297 4.9 46 BULK-ebe425e5
20664 Bulk Product d7d86a33 Sports & Outdoors $610.53 34 3.3 94 BULK-1e5b5111
20665 Bulk Product 4a3ec9c9 Clothing $406.55 225 1.2 23 BULK-df5d81d4
20666 Bulk Product 78e75cd7 Toys & Games $400.32 466 3.7 35 BULK-326ebb6e
20667 Bulk Product 399b4369 Toys & Games $633.88 315 1.8 12 BULK-8f6bc890
20668 Bulk Product 4782567d Home & Garden $169.41 166 4.8 17 BULK-f577db77
20669 Bulk Product b12f31c4 Toys & Games $342.97 236 2.9 99 BULK-bd23429b
20670 Bulk Product 7c2ed4bb Electronics $348.88 291 1.8 83 BULK-3424e52c
20671 Bulk Product c49be870 Books $222.68 257 1.6 89 BULK-d66f1e76
20672 Bulk Product 9cfae2b3 Clothing $599.35 51 1.1 12 BULK-38e899fb
20673 Bulk Product a5336bfe Electronics $175.23 49 3.0 19 BULK-b56904b7
20674 Bulk Product cf56766f Electronics $329.01 473 0.7 13 BULK-9c45b8bf
20675 Bulk Product 9599ed6b Home & Garden $572.32 16 3.9 20 BULK-59928fa2
20676 Bulk Product b7b455b0 Sports & Outdoors $437.42 213 1.2 3 BULK-a60b038a
20677 Bulk Product bf0554bb Clothing $585.55 212 2.7 17 BULK-f280fa59
20678 Bulk Product a1496bfb Clothing $119.20 453 2.9 9 BULK-11726fbc
20679 Bulk Product 0b8e6e88 Clothing $820.81 294 2.4 17 BULK-7dffe0d3
20680 Bulk Product 7c0e7a17 Clothing $748.06 31 0.6 25 BULK-fd2e3e6b
20681 Bulk Product 4f107980 Electronics $505.66 485 4.9 84 BULK-32caaf35
20682 Bulk Product 681a5bbd Home & Garden $847.39 117 0.0 72 BULK-d0a199e0
20683 Bulk Product 15f1b776 Home & Garden $32.42 329 3.0 79 BULK-750b84ce
20684 Bulk Product d67d2894 Electronics $944.38 38 3.1 42 BULK-b48d3918
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