Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

10 ms

Page Size

25

Current Page

410 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 410 Results Showing 10226 - 10250 of 24441

ID Name Category Price Stock Rating Reviews SKU
10785 Bulk Product dc89158f Books $522.81 178 2.3 21 BULK-71471c65
10786 Bulk Product f4883459 Sports & Outdoors $786.06 58 2.3 38 BULK-5045c637
10787 Bulk Product 1058480a Clothing $459.27 333 1.6 69 BULK-4d62c10d
10788 Bulk Product 97d6d4a7 Home & Garden $594.12 479 1.2 71 BULK-a0aa4a08
10789 Bulk Product 73a60d60 Clothing $58.43 238 4.3 80 BULK-c27d0b38
10790 Bulk Product f8726797 Sports & Outdoors $403.09 400 0.1 99 BULK-6731ed41
10791 Bulk Product fe4b5e5e Toys & Games $835.14 164 4.2 85 BULK-4422fd85
10792 Bulk Product 39f96ca3 Toys & Games $134.45 40 1.7 18 BULK-9a4e218d
10793 Bulk Product f3002dba Sports & Outdoors $535.32 166 3.4 78 BULK-88de01d3
10794 Bulk Product e585f6d4 Toys & Games $122.91 45 0.1 56 BULK-2b00a8c2
10795 Bulk Product 8de54108 Sports & Outdoors $952.05 455 4.8 0 BULK-5823d41f
10796 Bulk Product 3aee4f06 Clothing $517.22 399 4.1 62 BULK-ec362883
10797 Bulk Product 309cb7d7 Sports & Outdoors $146.63 35 2.2 48 BULK-092f82af
10798 Bulk Product 9be48693 Books $523.83 245 4.6 39 BULK-4a9fa43e
10799 Bulk Product b585e8dd Home & Garden $359.14 124 0.4 84 BULK-d2a0aede
10800 Bulk Product fa79b8de Home & Garden $879.23 425 3.0 68 BULK-912172b0
10801 Bulk Product fbd4a22b Toys & Games $779.12 451 4.3 2 BULK-bc18ba98
10802 Bulk Product 73d4f161 Sports & Outdoors $928.05 85 4.6 51 BULK-c38570a5
10803 Bulk Product 81bbdec7 Electronics $763.44 252 1.6 70 BULK-feea642d
10804 Bulk Product 1c3dc6b6 Toys & Games $760.43 327 3.5 48 BULK-a69bc7ff
10805 Bulk Product 0886aa48 Books $573.79 316 0.1 92 BULK-5bdffd02
10806 Bulk Product c2c29293 Clothing $496.23 90 1.0 35 BULK-31169a29
10807 Bulk Product 2bb623da Books $460.15 53 0.7 87 BULK-e5e3fd57
10808 Bulk Product 1720825b Books $42.00 435 2.8 10 BULK-5caf14de
10809 Bulk Product 6b6a8224 Clothing $814.44 254 3.2 41 BULK-41f8499d
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