Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

1642 ms

Page Size

25

Current Page

419 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 419 Results Showing 10451 - 10475 of 24441

ID Name Category Price Stock Rating Reviews SKU
11010 Bulk Product 87d85df4 Electronics $109.41 325 3.4 48 BULK-5c33425e
11011 Bulk Product a754c0da Home & Garden $381.35 411 3.6 7 BULK-3c18afd8
11012 Bulk Product 534f76a5 Toys & Games $193.35 309 3.3 22 BULK-f168869a
11013 Bulk Product 1c136586 Sports & Outdoors $443.65 436 0.2 83 BULK-377edce6
11014 Bulk Product 08bc6e09 Toys & Games $321.01 487 0.0 59 BULK-f91f03d4
11015 Bulk Product 0c0a2b2d Books $96.51 153 1.6 5 BULK-ee36a433
11016 Bulk Product f3456203 Electronics $561.19 263 0.3 71 BULK-4d5988af
11017 Bulk Product fa62c01e Electronics $820.20 29 2.4 98 BULK-31cb444a
11018 Bulk Product 6a7cbd28 Books $712.42 299 4.7 34 BULK-14566dc1
11019 Bulk Product 76915e27 Clothing $932.29 361 2.2 57 BULK-0e86f6e7
11020 Bulk Product 06ee9870 Electronics $213.19 495 3.3 90 BULK-0cf5e2a0
11021 Bulk Product 1d5bf189 Electronics $394.59 403 4.5 38 BULK-52527bce
11022 Bulk Product 85691033 Books $162.92 472 3.6 74 BULK-4d760ce0
11023 Bulk Product 39ca18d0 Books $511.02 168 4.8 55 BULK-0050724d
11024 Bulk Product 42a62e99 Electronics $206.08 64 2.8 14 BULK-7b4f0239
11025 Bulk Product 379925de Clothing $782.00 230 2.6 6 BULK-2d1f5e51
11026 Bulk Product 3f2692e7 Electronics $926.63 362 4.8 57 BULK-ce472710
11027 Bulk Product 4eab9810 Toys & Games $49.44 249 3.7 36 BULK-50dce2e4
11028 Bulk Product 42ed7cd6 Home & Garden $82.27 371 1.0 12 BULK-4812aa49
11029 Bulk Product 191eba24 Toys & Games $411.34 41 3.1 25 BULK-8cd59527
11030 Bulk Product a7d51f73 Clothing $28.80 431 0.6 1 BULK-41248636
11031 Bulk Product 26773482 Toys & Games $105.54 390 3.0 59 BULK-5604a6ad
11032 Bulk Product f70ebd64 Clothing $895.15 40 4.9 68 BULK-55904561
11033 Bulk Product 410869bf Books $429.36 248 3.9 82 BULK-3a01a299
11034 Bulk Product 4d3265f5 Clothing $139.05 380 2.8 83 BULK-ddab48f3
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