Difference between IQueryable<T> and IEnumerable<T>- .net

195
Views
1
Answers

What is the difference between IQueryable and IEnumerable?

edit | flag
William Patrick
Asked on: Jun 25, 2011 at 12:32AM

1 Answers

40
2
40

IQueryable extends the IEnumerable interface, so anything you can do with a "plain" IEnumerable, you can also do with an IQueryable.

IEnumerable just has a GetEnumerator() method that returns an Enumerator for which you can call its MoveNext() method to iterate through a sequence of T.

What IQueryable has that IEnumerable 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 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).

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.

edit | flag
Gokul A
Answered on: Jun 25, 2011 at 12:38AM

Post your Answer

Search

Welcome to Ask Amoeba!
This is 100% free and interactive site for sharing professional Questions and Answers, Opensource projects, Interview questions.
Learners, beginners, Experts stop and share your knowledge and ideas!

Browse Categories

Browse Tags