Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

14 ms

Page Size

25

Current Page

639 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 639 Results Showing 15951 - 15975 of 24441

ID Name Category Price Stock Rating Reviews SKU
16510 Bulk Product 603d3714 Electronics $783.75 51 2.7 47 BULK-44570766
16511 Bulk Product 9634a138 Books $657.01 476 3.8 76 BULK-1d2f9111
16512 Bulk Product 469bf13e Home & Garden $75.47 280 3.0 42 BULK-02082b79
16513 Bulk Product 63e3e3f8 Electronics $352.76 215 0.9 49 BULK-1bd9e923
16514 Bulk Product 971c2a26 Electronics $193.76 141 3.7 98 BULK-f725760d
16515 Bulk Product a7d850c5 Books $726.22 478 1.5 16 BULK-1e4cdf40
16516 Bulk Product 9b3824c0 Home & Garden $298.45 112 4.5 54 BULK-b8857afc
16517 Bulk Product 203d3c58 Books $58.00 190 4.6 97 BULK-d518385f
16518 Bulk Product c79981f3 Toys & Games $274.95 136 2.7 89 BULK-98e570eb
16519 Bulk Product 56a3438c Clothing $834.80 252 3.2 18 BULK-af759cef
16520 Bulk Product 0601697b Books $651.37 4 1.6 16 BULK-5da166e4
16521 Bulk Product 5b8f22cd Toys & Games $248.72 183 2.4 92 BULK-574cf9fe
16522 Bulk Product 8f85ed05 Books $817.88 250 2.0 89 BULK-9ca8fa9e
16523 Bulk Product 6780325e Electronics $611.23 477 1.4 63 BULK-16e59190
16524 Bulk Product c290be6b Books $542.04 322 3.1 44 BULK-8dd3f8ed
16525 Bulk Product ece435bd Clothing $970.46 400 2.6 8 BULK-3ac5951d
16526 Bulk Product cb426d8b Clothing $876.78 464 0.9 28 BULK-99dd310b
16527 Bulk Product 4f65c008 Home & Garden $862.71 358 2.3 88 BULK-22d3c4e3
16528 Bulk Product 523de36f Toys & Games $621.60 254 4.6 40 BULK-bab4e63a
16529 Bulk Product 902286e0 Clothing $385.96 470 3.6 9 BULK-fc37eb36
16530 Bulk Product 3353db96 Home & Garden $242.68 49 4.6 40 BULK-65b7aac7
16531 Bulk Product fd7b8e0c Clothing $756.37 251 2.4 35 BULK-d2521cb0
16532 Bulk Product e18a77b4 Sports & Outdoors $871.94 368 4.6 46 BULK-304b1f6c
16533 Bulk Product f584ac55 Electronics $69.72 243 4.7 67 BULK-1f95e78b
16534 Bulk Product 9e71483d Sports & Outdoors $878.33 345 2.9 22 BULK-e8cd765a
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