Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

18 ms

Page Size

25

Current Page

960 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 960 Results Showing 23976 - 24000 of 24441

ID Name Category Price Stock Rating Reviews SKU
24535 Bulk Product 70013059 Toys & Games $827.76 131 3.1 43 BULK-44eddb3c
24536 Bulk Product ed948a99 Home & Garden $39.14 299 4.4 96 BULK-736a9948
24537 Bulk Product 81850e2b Toys & Games $493.40 151 0.1 69 BULK-734ebfea
24538 Bulk Product 0526232e Home & Garden $328.21 373 3.7 92 BULK-51ce4958
24539 Bulk Product 664999c7 Electronics $314.63 18 2.4 68 BULK-05630431
24540 Bulk Product 9688d099 Electronics $342.52 394 4.6 83 BULK-7e43aa96
24541 Bulk Product 0219af47 Books $540.19 71 0.2 65 BULK-c036c826
24542 Bulk Product 06515dc2 Sports & Outdoors $841.69 74 0.3 89 BULK-8f80c77d
24543 Bulk Product 56e2c976 Sports & Outdoors $179.09 12 1.0 36 BULK-aa31f9ae
24544 Bulk Product b226d281 Books $271.07 295 4.0 47 BULK-28e196cb
24545 Bulk Product a9e3b3ec Books $963.70 50 4.6 88 BULK-3d4fd8c1
24546 Bulk Product 224698b9 Electronics $982.09 30 1.4 50 BULK-800b8a42
24547 Bulk Product 752c1b05 Home & Garden $106.48 369 4.6 48 BULK-3eb8cd9d
24548 Bulk Product 5d32c756 Toys & Games $947.52 30 4.8 78 BULK-e1f56041
24549 Bulk Product 3f542f9c Electronics $595.96 67 1.1 11 BULK-427fe164
24550 Bulk Product 92e36938 Sports & Outdoors $792.98 443 2.6 76 BULK-b7676538
24551 Bulk Product 9b6f927b Sports & Outdoors $396.58 282 3.9 72 BULK-e654ed37
24552 Bulk Product f87b8edd Books $219.87 381 4.8 94 BULK-7ed9a769
24553 Bulk Product 957f373a Clothing $957.49 425 2.6 70 BULK-c5fea4c7
24554 Bulk Product 1df4c514 Clothing $885.95 243 0.4 27 BULK-316f9bb5
24555 Bulk Product 0fa9d63e Sports & Outdoors $272.59 424 0.7 16 BULK-13a5f2ab
24556 Bulk Product b98623bf Home & Garden $510.86 61 4.5 57 BULK-aa6d002f
24557 Bulk Product 711439d4 Sports & Outdoors $903.79 362 4.3 51 BULK-ff6621f8
24558 Bulk Product a1e59be5 Clothing $611.41 184 2.2 38 BULK-93c7721d
24559 Bulk Product 10c30ea2 Toys & Games $375.95 433 2.0 48 BULK-8b7faf71
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