Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

19 ms

Page Size

25

Current Page

844 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 844 Results Showing 21076 - 21100 of 24441

ID Name Category Price Stock Rating Reviews SKU
21635 Bulk Product 61b82cb9 Home & Garden $146.05 246 4.7 71 BULK-1da208e4
21636 Bulk Product 929ef052 Clothing $906.68 298 4.1 20 BULK-43e772d9
21637 Bulk Product 881e687f Clothing $684.31 141 1.4 5 BULK-c25e6416
21638 Bulk Product 68209024 Electronics $801.66 191 4.0 46 BULK-88625820
21639 Bulk Product 47f5de1c Home & Garden $174.36 422 0.2 94 BULK-0b5c15db
21640 Bulk Product ea28a759 Toys & Games $261.28 424 0.5 42 BULK-6fb1aefa
21641 Bulk Product f1c3c2d8 Clothing $662.80 102 2.7 70 BULK-24696f1b
21642 Bulk Product 2df9c51c Clothing $107.33 290 4.0 67 BULK-1441f566
21643 Bulk Product 3193008d Sports & Outdoors $729.40 152 1.7 98 BULK-536e8320
21644 Bulk Product d0840a43 Toys & Games $58.67 347 0.4 7 BULK-a7c52e21
21645 Bulk Product 3c102a50 Sports & Outdoors $780.09 346 3.5 65 BULK-a027a2d1
21646 Bulk Product 6b2c949d Books $976.56 137 3.3 44 BULK-7b04197e
21647 Bulk Product 5ada33d9 Electronics $343.43 407 1.0 36 BULK-4c21759b
21648 Bulk Product e7ec6076 Sports & Outdoors $518.65 281 2.6 67 BULK-b0685ba9
21649 Bulk Product 387252f9 Books $941.23 39 4.0 59 BULK-a1d1d00f
21650 Bulk Product 45efd838 Toys & Games $759.80 395 2.9 98 BULK-2736d301
21651 Bulk Product 4c262981 Toys & Games $418.15 8 3.5 43 BULK-ffc564e4
21652 Bulk Product b827fbfa Home & Garden $326.34 334 0.8 71 BULK-01cfa29d
21653 Bulk Product c084ed85 Clothing $221.47 234 3.1 93 BULK-2a1c570f
21654 Bulk Product c8544cf3 Home & Garden $586.45 200 1.9 76 BULK-89aeb15e
21655 Bulk Product c64f0439 Toys & Games $644.57 236 4.7 84 BULK-f87495de
21656 Bulk Product eda9b9a1 Clothing $378.09 171 4.4 81 BULK-310e6bd1
21657 Bulk Product 21817395 Electronics $507.91 331 0.8 71 BULK-d988b40c
21658 Bulk Product 5462ed73 Toys & Games $171.79 475 1.3 56 BULK-7e49e80d
21659 Bulk Product 2a66c999 Books $414.52 171 2.4 54 BULK-347deddc
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