Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

12 ms

Page Size

25

Current Page

521 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 521 Results Showing 13001 - 13025 of 24441

ID Name Category Price Stock Rating Reviews SKU
13560 Bulk Product f9d835ff Books $857.86 464 3.6 82 BULK-de2e4a69
13561 Bulk Product 498591d2 Toys & Games $163.08 173 4.1 65 BULK-aa13eadf
13562 Bulk Product 00bd861e Sports & Outdoors $345.19 119 1.2 57 BULK-c839d744
13563 Bulk Product d7d7a5f0 Sports & Outdoors $45.84 180 4.6 13 BULK-026f2ff5
13564 Bulk Product bce91e7a Electronics $423.92 80 4.3 21 BULK-838d87c6
13565 Bulk Product 7385c6c6 Home & Garden $248.13 457 1.3 51 BULK-d7515b23
13566 Bulk Product f1023a94 Home & Garden $511.70 313 1.4 35 BULK-9c252ed8
13567 Bulk Product de6954e9 Electronics $923.31 396 3.5 26 BULK-8c1ebfd1
13568 Bulk Product 887edae7 Toys & Games $336.40 266 0.4 70 BULK-fbbbbc9a
13569 Bulk Product 3bb75a5e Books $22.30 309 3.9 77 BULK-3cffa80c
13570 Bulk Product cf5921eb Books $881.61 172 1.6 93 BULK-2643dba6
13571 Bulk Product bf514055 Toys & Games $852.77 247 2.5 11 BULK-34d4dbaf
13572 Bulk Product 6767e191 Clothing $543.46 377 1.8 39 BULK-c8d226db
13573 Bulk Product 0a85facc Home & Garden $709.43 400 4.5 31 BULK-53299745
13574 Bulk Product 0e79367b Toys & Games $878.95 101 3.1 33 BULK-52fdac74
13575 Bulk Product 264bffe1 Electronics $461.91 205 4.2 41 BULK-edee062b
13576 Bulk Product 6deeee8d Sports & Outdoors $352.18 41 3.5 88 BULK-51a4b4ff
13577 Bulk Product 915d4843 Books $175.98 211 3.7 0 BULK-ce9ec338
13578 Bulk Product e91c8fd5 Toys & Games $282.37 9 2.1 45 BULK-581f58fd
13579 Bulk Product 84be2cd7 Books $905.52 322 0.3 67 BULK-7afd0ed3
13580 Bulk Product 2418ba2c Home & Garden $416.46 396 3.3 78 BULK-164560f6
13581 Bulk Product e508dfee Books $447.90 6 3.9 38 BULK-572468f2
13582 Bulk Product 0dca1aba Electronics $133.48 430 1.2 86 BULK-e80ce61a
13583 Bulk Product e20b67c5 Toys & Games $263.48 489 3.5 66 BULK-a40025f4
13584 Bulk Product 4179bd1d Clothing $836.88 143 2.4 50 BULK-a4af75c0
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