简体   繁体   English

为什么更喜欢在IEnumerable上使用linq on IQueryable over linq?

[英]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. 我知道我可以在实现IQueryable或IEnumerable的集合上使用linq语法。

Does IQueryable use lazy calaulation and optimization, while IEnumerable not? IQueryable是否使用延迟的calaulation和优化,而IEnumerable不是吗?

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. IEnumerable上的Linq使用Linq到对象 - IQueryable上的Linq正在使用查询提供程序为标准查询运算符实现的任何内容。

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. 对于像Linq to SQL和Entity Framework这样的ORM,即这意味着将Linq查询转换为数据库上相应的SQL查询 - 对数据库进行过滤等比将所有数据移动到内存中更为可取,因为它将具有更好的性能。

No, IQueryable is typically supported by database-oriented providers and supports translation to SQL. 不,IQueryable通常由面向数据库的提供程序支持,并支持转换为SQL。
Any optimizations would be due to the SQL engine. 任何优化都归功于SQL引擎。

Both IQueryable and IEnumerable have deferred execution. IQueryable和IEnumerable都延迟执行。
interface IQueryable<T> : IEnumerable<T> ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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