Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

21 ms

Page Size

25

Current Page

523 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 523 Results Showing 13051 - 13075 of 24441

ID Name Category Price Stock Rating Reviews SKU
13610 Bulk Product 6db9a6f1 Toys & Games $266.68 38 2.1 26 BULK-b92563a8
13611 Bulk Product feb8c1f5 Home & Garden $894.39 388 0.3 12 BULK-35de84b4
13612 Bulk Product 11e4d3e1 Books $666.88 256 4.3 97 BULK-976c8025
13613 Bulk Product 73917219 Electronics $259.08 257 3.7 40 BULK-681777d3
13614 Bulk Product eaa29c4b Electronics $521.52 60 0.2 70 BULK-3b094dda
13615 Bulk Product 67aa8594 Home & Garden $258.63 327 2.8 74 BULK-6543eb06
13616 Bulk Product 86c1eeed Books $934.08 353 4.6 61 BULK-ae0f211e
13617 Bulk Product bb812d70 Sports & Outdoors $239.55 22 0.8 16 BULK-05c0844f
13618 Bulk Product 08ec5693 Toys & Games $119.08 470 1.6 51 BULK-87ce391e
13619 Bulk Product abf3f934 Electronics $559.76 131 4.2 7 BULK-cdd74263
13620 Bulk Product 5df7c74e Sports & Outdoors $249.37 453 3.0 95 BULK-326d51d2
13621 Bulk Product b97016b2 Clothing $27.66 66 3.1 65 BULK-302a3f8c
13622 Bulk Product e02fdad8 Clothing $991.84 370 0.3 86 BULK-2e6314f3
13623 Bulk Product e91ad5b6 Sports & Outdoors $550.17 492 4.0 90 BULK-85318120
13624 Bulk Product 0425dcd0 Clothing $413.18 415 1.9 82 BULK-05ac9f86
13625 Bulk Product b57cce92 Books $395.49 182 4.0 54 BULK-466513dd
13626 Bulk Product b0286463 Electronics $921.89 155 0.1 45 BULK-a33db946
13627 Bulk Product a15047d4 Toys & Games $443.95 182 1.7 87 BULK-f15eddc1
13628 Bulk Product 8adb44da Sports & Outdoors $217.01 273 1.5 97 BULK-0eadb4b5
13629 Bulk Product 32e98332 Toys & Games $709.12 497 1.8 48 BULK-f508f33a
13630 Bulk Product b7fa58f0 Toys & Games $268.31 436 2.5 81 BULK-e29f3f3e
13631 Bulk Product 97b49dbf Home & Garden $969.35 314 1.3 12 BULK-77588c11
13632 Bulk Product 341ba57f Clothing $470.54 86 0.2 72 BULK-146e9d7d
13633 Bulk Product 811599b4 Books $85.91 141 4.3 88 BULK-268add49
13634 Bulk Product 1c5de4f7 Books $362.31 290 2.7 28 BULK-77a6f54a
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