Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

56 ms

Page Size

25

Current Page

798 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 798 Results Showing 19926 - 19950 of 24441

ID Name Category Price Stock Rating Reviews SKU
20485 Bulk Product d5208f5a Books $61.11 22 2.2 61 BULK-27915c8c
20486 Bulk Product d4e713e5 Home & Garden $18.99 190 0.7 9 BULK-9eca0eb7
20487 Bulk Product 7d0db8f2 Electronics $786.43 461 4.3 38 BULK-1ce85a32
20488 Bulk Product f56e9c5b Books $742.15 177 5.0 5 BULK-73b28aca
20489 Bulk Product 85abf5f0 Clothing $164.15 491 1.2 50 BULK-4100f557
20490 Bulk Product f26d0130 Clothing $942.64 386 0.3 62 BULK-e4256827
20491 Bulk Product db148696 Clothing $831.07 340 1.7 21 BULK-66ef1b9d
20492 Bulk Product 191c8a9d Toys & Games $830.20 373 2.0 27 BULK-cbd39662
20493 Bulk Product 0db7e2b6 Toys & Games $697.52 486 2.7 26 BULK-588bc075
20494 Bulk Product 2583bec6 Sports & Outdoors $266.27 165 2.0 51 BULK-035ae6b9
20495 Bulk Product f98bc016 Home & Garden $727.25 332 4.1 40 BULK-9b2423fb
20496 Bulk Product 3646c336 Sports & Outdoors $737.90 92 0.3 45 BULK-4d219c8f
20497 Bulk Product cc3cfd96 Sports & Outdoors $466.99 31 4.8 80 BULK-7b51c819
20498 Bulk Product 0c1d5356 Home & Garden $843.80 240 0.6 31 BULK-2d255c99
20499 Bulk Product 363e3c7a Clothing $904.04 283 2.2 41 BULK-e4874fd5
20500 Bulk Product 1c9c480e Sports & Outdoors $590.18 376 1.2 88 BULK-e87ae13f
20501 Bulk Product 6983c70f Electronics $335.63 222 2.1 80 BULK-64294ee1
20502 Bulk Product 2cd9c67e Books $739.74 386 2.7 44 BULK-1e4fd927
20503 Bulk Product 6c175015 Home & Garden $210.77 106 2.6 92 BULK-5a7d9572
20504 Bulk Product c231ab08 Clothing $270.98 441 0.7 10 BULK-cc899d10
20505 Bulk Product 2ae29b85 Home & Garden $743.44 370 4.9 39 BULK-1f20da04
20506 Bulk Product 8c2ea5e8 Sports & Outdoors $66.94 367 4.5 6 BULK-046deecf
20507 Bulk Product 69713f44 Sports & Outdoors $639.38 140 2.8 96 BULK-ea4614fd
20508 Bulk Product c9b87c97 Electronics $447.52 412 1.1 14 BULK-30344a39
20509 Bulk Product 8e7d3522 Toys & Games $850.44 48 0.0 27 BULK-9a4601b6
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