Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

18 ms

Page Size

25

Current Page

246 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 246 Results Showing 6126 - 6150 of 24441

ID Name Category Price Stock Rating Reviews SKU
6685 Bulk Product 48482a6e Sports & Outdoors $982.72 176 2.6 51 BULK-a99b7f65
6686 Bulk Product ee3c0719 Home & Garden $424.46 498 0.8 30 BULK-8b262f83
6687 Bulk Product 839951a1 Electronics $429.91 4 1.8 25 BULK-fc4eceb6
6688 Bulk Product e3cbf593 Home & Garden $356.46 138 1.5 68 BULK-9e163f6f
6689 Bulk Product b7254af7 Clothing $521.58 490 4.2 27 BULK-09f4eabc
6690 Bulk Product 90e2d0e1 Toys & Games $636.43 216 3.3 1 BULK-648834b0
6691 Bulk Product 91b9e207 Clothing $942.60 229 2.4 6 BULK-f589f66d
6692 Bulk Product ce34179b Home & Garden $894.94 108 2.8 80 BULK-82a06de3
6693 Bulk Product 34a319e2 Toys & Games $945.69 307 0.3 95 BULK-8892e1ed
6694 Bulk Product d3e47975 Clothing $872.09 317 3.6 61 BULK-ddef9eba
6695 Bulk Product a9a6834a Home & Garden $27.45 152 0.7 64 BULK-10099512
6696 Bulk Product c027c591 Clothing $897.85 477 4.4 91 BULK-62532f9d
6697 Bulk Product 45671535 Electronics $593.18 232 0.7 54 BULK-c07a1071
6698 Bulk Product 797341ed Toys & Games $533.72 4 1.6 61 BULK-2b251272
6699 Bulk Product 7dfa9007 Books $142.58 482 0.6 77 BULK-56e83a1d
6700 Bulk Product af53270b Toys & Games $729.19 284 1.7 15 BULK-729bbeb9
6701 Bulk Product e6d8fde9 Toys & Games $557.00 275 0.6 88 BULK-092801e5
6702 Bulk Product e7005fdb Electronics $249.31 20 4.4 12 BULK-8c5dfaa2
6703 Bulk Product b6ba14c8 Books $968.61 432 2.8 59 BULK-220e1514
6704 Bulk Product ab45622a Toys & Games $966.80 96 1.2 3 BULK-48bb6272
6705 Bulk Product 3af604f1 Toys & Games $958.61 171 1.2 1 BULK-9aea98e1
6706 Bulk Product f66e14ed Clothing $86.93 178 1.5 3 BULK-4b4a9580
6707 Bulk Product 16eda81a Electronics $32.03 495 3.4 19 BULK-68ca674a
6708 Bulk Product 59fa2b69 Electronics $987.90 380 3.3 61 BULK-3284a5d3
6709 Bulk Product c65f8001 Electronics $559.82 97 0.2 34 BULK-81c8ba97
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