Deferred execution trì hoãn việc thực thi query cho đến khi dữ liệu thực sự được truy cập — var result = collection.Where(x => x > 5) chưa chạy cho đến khi bạn iterate hoặc gọi ToList().
- Immediate execution chạy ngay lập tức:
ToList(),ToArray(),Count(),First(). - Hầu hết LINQ operators dùng deferred execution.
- Hiểu rõ khi nào query thực sự chạy để tránh bug khó tìm.
Deferred execution delays query evaluation until data is accessed — var result = collection.Where(x => x > 5) does not execute until you iterate or call ToList().
- Immediate execution runs right away:
ToList(),ToArray(),Count(),First(). - Most LINQ operators use deferred execution.
- Understanding when queries actually run is key to avoiding subtle bugs.