Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

11 ms

Page Size

25

Current Page

381 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 381 Results Showing 9501 - 9525 of 24441

ID Name Category Price Stock Rating Reviews SKU
10060 Bulk Product 716b0331 Sports & Outdoors $498.29 7 3.6 70 BULK-029b19f6
10061 Bulk Product 2c2a3444 Toys & Games $853.01 166 4.0 94 BULK-e93d38ff
10062 Bulk Product ed1fe035 Home & Garden $268.61 109 1.4 61 BULK-03e46848
10063 Bulk Product 272533a5 Home & Garden $610.19 3 0.2 18 BULK-fedf4565
10064 Bulk Product fa418b6a Sports & Outdoors $715.11 255 1.4 98 BULK-d8da9013
10065 Bulk Product 51f7cf17 Sports & Outdoors $508.75 260 1.0 33 BULK-7cd27e52
10066 Bulk Product 5e39bc02 Home & Garden $892.57 237 3.9 26 BULK-24eea4dd
10067 Bulk Product fc3af787 Toys & Games $746.10 228 2.9 21 BULK-418c039d
10068 Bulk Product 57a5482e Sports & Outdoors $896.51 115 2.8 63 BULK-72d231eb
10069 Bulk Product f52d73ed Books $214.64 443 1.8 13 BULK-791352d6
10070 Bulk Product 44ef1a49 Electronics $870.96 459 4.8 86 BULK-a7db6639
10071 Bulk Product 8c908784 Sports & Outdoors $538.43 306 3.3 8 BULK-9c540fb9
10072 Bulk Product fc0ace7d Electronics $11.83 399 4.3 87 BULK-7d4ed941
10073 Bulk Product 3c1bc4fc Books $907.01 314 3.1 69 BULK-fc9c6e22
10074 Bulk Product 63965252 Home & Garden $793.23 214 1.5 99 BULK-74b04a97
10075 Bulk Product 9397ff58 Clothing $621.39 434 0.1 14 BULK-95c977c0
10076 Bulk Product 496d1cb6 Books $262.73 402 4.0 69 BULK-d9c4e94b
10077 Bulk Product 7cdc8872 Home & Garden $408.49 130 3.9 41 BULK-32b97491
10078 Bulk Product 4381e9a5 Clothing $670.30 439 4.4 54 BULK-bb52eb04
10079 Bulk Product 9c180c2a Electronics $64.37 197 0.7 88 BULK-9c70b089
10080 Bulk Product e879eb48 Home & Garden $628.38 314 0.7 92 BULK-7a60d353
10081 Bulk Product 72bd3aab Clothing $15.53 121 2.7 13 BULK-0b260aa5
10082 Bulk Product 093fedef Electronics $36.30 61 2.6 59 BULK-7f2134f6
10083 Bulk Product 51255878 Clothing $123.45 420 4.5 39 BULK-9dab6d7d
10084 Bulk Product 5dcae3d9 Home & Garden $616.18 438 3.3 43 BULK-feeb79c3
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