问题描述
之间的区别是什么的IQueryable< T>
和的IEnumerable< T>
另请参见<一个href="http://stackoverflow.com/questions/2433306/whats-the-difference-between-iqueryable-and-ienumerable?rq=1">What's与此问题重叠的IQueryable和IEnumerable 的之间的差异。
See also What's the difference between IQueryable and IEnumerable that overlaps with this question.
推荐答案
首先,的IQueryable&LT;吨> 的扩展的了IEnumerable&LT; T>接口,所以任何你可以用一个普通的IEnumerable&LT做; T>,你也可以做一个IQueryable&LT; T>。
First of all, IQueryable<T> extends the IEnumerable<T> interface, so anything you can do with a "plain" IEnumerable<T>, you can also do with an IQueryable<T>.
的IEnumerable&LT; T>只是有一个的的GetEnumerator()的方法,该方法返回的枚举&LT; T> 的,而您可以调用它的的MoveNext()方法遍历序列的 T 的。
IEnumerable<T> just has a GetEnumerator() method that returns an Enumerator<T> for which you can call its MoveNext() method to iterate through a sequence of T.
什么的IQueryable&LT; T>有一个IEnumerable的&LT; T>的不的是特别,一个指向一个查询提供(例如,LINQ到两个属性SQL提供)和另一个指向的查询前pression 强>重新presenting所述的IQueryable&所述; T>对象作为一个运行时,可穿越前pression可以由给定的被理解查询供应商(在大多数情况下,你不能给一个LINQ到SQL EX pression到LINQ到实体提供未出现异常被抛出)。
What IQueryable<T> has that IEnumerable<T> doesn't are two properties in particular—one that points to a query provider (e.g., a LINQ to SQL provider) and another one pointing to a query expression representing the IQueryable<T> object as a runtime-traversable expression that can be understood by the given query provider (for the most part, you can't give a LINQ to SQL expression to a LINQ to Entities provider without an exception being thrown).
的前pression可以简单地是对象本身或一个更复杂的一个组成的组查询运算符和操作数的树的恒定前pression。查询供应商的的 IQueryProvider.Execute()或 IQueryProvider.CreateQuery()的方法被称为具有的防爆pression 的传递给它,然后是一个查询结果或其他IQueryable的返回,分别为。
The expression can simply be a constant expression of the object itself or a more complex tree of a composed set of query operators and operands. The query provider's IQueryProvider.Execute() or IQueryProvider.CreateQuery() methods are called with an Expression passed to it, and then either a query result or another IQueryable is returned, respectively.
这篇关于是什么IQueryable的和之间的差; T&GT;和IEnumerable&LT; T&GT;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!