简体   繁体   中英

Does First() in LINQ cause eager or lazy loading?

I have a query:

db.Order.Include("OrderItem").First(r => r.Id == OrderId)
  1. Does First() on it own cause Eager or Lazy loading?
  2. If not then how would you force Eager loading for a First()?
  3. Is the above combined query Eagerly or lazily loaded?

First() and FirstOrDefault() are executed immediately (eager) at the point where they're called.

All standard LINQ operators, which return a single, non-enumerable result, and those that do not return an explicit IEnumerable<T> , are executed immediately.

See Classification of Standard Query Operators by Manner of Execution for the complete list of LINQ operators.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM