简体   繁体   中英

Why to prefer using linq on IQueryable over linq on IEnumerable?

I know I can use linq syntax on collections that implement IQueryable or IEnumerable.

Does IQueryable use lazy calaulation and optimization, while IEnumerable not?

Does optimization include reordering of the queries?

Linq on an IEnumerable is using Linq to Objects - Linq on an IQueryable is using whatever the query provider has implemented for the standard query operators.

For ORMs like Linq to SQL and Entity Framework ie that means translating your Linq query into the corresponding SQL query on the database - filtering etc. on the database is much preferred to moving all that data into memory as it will have much better performance.

No, IQueryable is typically supported by database-oriented providers and supports translation to SQL.
Any optimizations would be due to the SQL engine.

Both IQueryable and IEnumerable have deferred execution.
interface IQueryable<T> : IEnumerable<T> ...

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