Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

46 ms

Page Size

25

Current Page

600 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 600 Results Showing 14976 - 15000 of 24441

ID Name Category Price Stock Rating Reviews SKU
15535 Bulk Product d20cb10c Electronics $491.11 165 1.5 46 BULK-2ab3cf56
15536 Bulk Product 1bb34fbf Toys & Games $499.30 209 2.3 47 BULK-d6739aa6
15537 Bulk Product cd0f4e9f Books $703.05 461 4.6 37 BULK-e98cda34
15538 Bulk Product fcfbbafe Sports & Outdoors $744.33 16 1.7 31 BULK-87c51839
15539 Bulk Product 32561bcd Home & Garden $551.12 289 0.5 7 BULK-51d9db21
15540 Bulk Product c00ed6e7 Toys & Games $90.54 304 3.9 17 BULK-bf23e289
15541 Bulk Product 50489817 Home & Garden $669.46 78 1.4 2 BULK-0e6969ee
15542 Bulk Product b0c10708 Clothing $852.97 417 3.5 71 BULK-2135720c
15543 Bulk Product b4f334f3 Sports & Outdoors $421.30 289 2.3 42 BULK-d9488306
15544 Bulk Product a2d72847 Electronics $206.36 52 4.0 4 BULK-c5fa4d58
15545 Bulk Product 42845e66 Toys & Games $289.70 66 2.3 16 BULK-2c14cadd
15546 Bulk Product 91519574 Toys & Games $653.29 171 2.2 78 BULK-50ff2362
15547 Bulk Product 1bb70cbe Clothing $408.08 396 3.1 44 BULK-cd1b1946
15548 Bulk Product 5873ca0e Books $902.08 489 2.1 58 BULK-7784a741
15549 Bulk Product 3342a975 Sports & Outdoors $603.11 284 2.7 11 BULK-ba7811c2
15550 Bulk Product 91d93279 Sports & Outdoors $797.59 189 3.4 29 BULK-7180f9a8
15551 Bulk Product e609b8a3 Books $405.97 53 2.3 12 BULK-0e74d248
15552 Bulk Product 8cd59695 Books $598.34 261 1.9 32 BULK-52be4589
15553 Bulk Product b50c06eb Electronics $64.40 294 1.0 64 BULK-de1058c2
15554 Bulk Product b5ea9bdb Home & Garden $691.83 96 2.0 74 BULK-a0627b17
15555 Bulk Product a8ffe93c Electronics $514.41 315 4.0 5 BULK-43686944
15556 Bulk Product 0729ae98 Books $420.93 300 1.3 69 BULK-7866ec59
15557 Bulk Product 365fa373 Home & Garden $99.23 126 4.9 63 BULK-bd46f6f5
15558 Bulk Product 5098085c Electronics $520.43 497 0.3 97 BULK-08677ef9
15559 Bulk Product da1263c0 Toys & Games $869.72 357 1.6 96 BULK-386e4524
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