Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

35 ms

Page Size

25

Current Page

817 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 817 Results Showing 20401 - 20425 of 24441

ID Name Category Price Stock Rating Reviews SKU
20960 Bulk Product de6d1c2f Electronics $992.62 82 0.2 17 BULK-e2bb4a37
20961 Bulk Product 5882f8a9 Sports & Outdoors $527.76 365 5.0 65 BULK-92a60d7a
20962 Bulk Product 78139ed4 Books $268.40 16 1.9 24 BULK-55978a8b
20963 Bulk Product 19414eb0 Toys & Games $853.45 229 4.0 12 BULK-cb8ce5fc
20964 Bulk Product fb545955 Toys & Games $273.76 232 4.6 72 BULK-20d6b9ff
20965 Bulk Product df678e6e Books $160.43 163 1.1 11 BULK-006473d3
20966 Bulk Product 12a1e0ec Toys & Games $343.78 473 1.7 96 BULK-0e1e54db
20967 Bulk Product a92b483e Sports & Outdoors $938.84 230 2.6 94 BULK-36f9c97a
20968 Bulk Product b183ce4a Clothing $259.75 95 1.7 36 BULK-1d83ad16
20969 Bulk Product 92b51eff Sports & Outdoors $413.38 252 3.9 90 BULK-db21f823
20970 Bulk Product 6d1516eb Toys & Games $536.14 332 4.5 36 BULK-094ee347
20971 Bulk Product d7f6c6bb Electronics $211.48 277 0.0 63 BULK-40303c8b
20972 Bulk Product 3b871800 Electronics $399.85 452 0.8 34 BULK-dd6af2e2
20973 Bulk Product 43ba8ffd Electronics $730.22 160 0.6 66 BULK-3247d1c1
20974 Bulk Product 4e34e199 Home & Garden $951.12 158 3.5 95 BULK-82cba27e
20975 Bulk Product 7696a4de Books $843.42 292 3.1 33 BULK-cf58ed31
20976 Bulk Product b5a1a618 Sports & Outdoors $253.95 417 1.8 31 BULK-d9142e10
20977 Bulk Product a959a1e2 Clothing $891.19 344 1.1 87 BULK-24e99c56
20978 Bulk Product 303ccce6 Electronics $665.88 110 0.5 96 BULK-8c8bf425
20979 Bulk Product 6ce173f1 Home & Garden $725.82 23 2.0 10 BULK-4a4628a9
20980 Bulk Product 07db1424 Electronics $523.49 428 2.5 76 BULK-13f1c0b9
20981 Bulk Product 692149cb Electronics $278.72 106 0.4 35 BULK-72bf37d5
20982 Bulk Product 22744e77 Books $405.14 398 1.2 2 BULK-c0f2ada0
20983 Bulk Product 01b1d8c1 Electronics $106.85 130 4.4 76 BULK-4dcc5f8c
20984 Bulk Product d391eb5d Books $581.39 236 1.8 49 BULK-030e6ea3
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