Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

25 ms

Page Size

25

Current Page

741 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 741 Results Showing 18501 - 18525 of 24441

ID Name Category Price Stock Rating Reviews SKU
19060 Bulk Product 2bd35fab Toys & Games $81.59 108 2.8 19 BULK-396a279d
19061 Bulk Product ffa189ad Books $636.97 52 1.9 17 BULK-7549c2ca
19062 Bulk Product f3ac0479 Home & Garden $137.45 264 0.6 87 BULK-7be1e56e
19063 Bulk Product a6760027 Electronics $215.79 99 3.2 76 BULK-14461853
19064 Bulk Product eb709932 Toys & Games $577.68 379 0.0 85 BULK-05389827
19065 Bulk Product b6dc9799 Clothing $222.41 252 1.4 57 BULK-8a54898f
19066 Bulk Product 944f4c0c Sports & Outdoors $945.06 470 2.8 29 BULK-ad10f7d0
19067 Bulk Product 80586feb Clothing $966.85 272 3.9 74 BULK-aba8640a
19068 Bulk Product 81fadc11 Home & Garden $42.23 416 2.0 20 BULK-0e66888d
19069 Bulk Product 617f1c27 Books $351.17 437 3.9 44 BULK-c0940d30
19070 Bulk Product 5a759aff Books $141.08 247 4.5 85 BULK-c93e8169
19071 Bulk Product 972e7aac Toys & Games $591.32 27 4.3 45 BULK-fec55567
19072 Bulk Product b3c377d0 Home & Garden $610.15 170 0.8 76 BULK-1a8e67ce
19073 Bulk Product 9c857654 Electronics $17.31 320 0.9 11 BULK-92b9546f
19074 Bulk Product 5681b8ab Sports & Outdoors $22.03 215 1.3 0 BULK-b5de5fbb
19075 Bulk Product 8b1e80a2 Toys & Games $396.99 467 2.3 84 BULK-980e242d
19076 Bulk Product d42ec633 Books $777.35 306 3.1 9 BULK-40f49c54
19077 Bulk Product b39d9946 Sports & Outdoors $560.03 315 1.5 63 BULK-84404745
19078 Bulk Product dd28f12a Sports & Outdoors $65.43 127 2.5 62 BULK-48801ac6
19079 Bulk Product 9217a5a1 Books $360.73 473 4.4 3 BULK-483399b4
19080 Bulk Product 6287f7f4 Toys & Games $386.77 88 1.1 37 BULK-69c36d0c
19081 Bulk Product 6c90ca7f Clothing $631.72 223 1.4 98 BULK-f71f6dfa
19082 Bulk Product 4234e275 Toys & Games $539.74 164 4.9 32 BULK-14b48bb6
19083 Bulk Product fdaf60f4 Clothing $614.31 155 0.1 91 BULK-1de70218
19084 Bulk Product 0ebbbaba Electronics $791.53 337 3.8 46 BULK-30988951
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