What is the difference between IEnumerable and IQuearable in LINQ ? I read the more article on this but i doesn't understand the practicle diffrence.
-
6In fact, **accept some answers** - I'll remove my answer until you do.. – Barrie Reader Dec 14 '10 at 09:44
-
possible duplicate of [What is the difference between IQueryable
and IEnumerable – Kirk Woll Jan 16 '11 at 18:42?](http://stackoverflow.com/questions/252785/what-is-the-difference-between-iqueryablet-and-ienumerablet) -
People! It is inconceivable that this question would not be a dup. Practice due-diligence. – Kirk Woll Jan 16 '11 at 18:44
2 Answers
IEnumerable and IQueryable are the two most used terms of any LINQ discussion. What I am trying to here is that I am trying to simplify the two interfaces depending on their behavior. In LINQ world we generally have few providers available within .NET Framework, like LINQ to Object, LINQ to SQL, LINQ to XML.
It is a statement that every LINQ statement returns IEnumerable. IEnumerable works in steps. Meaning, when you write,
var q = from a in b
where a > 5
select a;
It creates a list out “b” depending on “where” then it creates another list for “select”. This is the behavior of LINQ to Object and LINQ to XML.
When you use LINQ to SQL it uses IQueryable. This interface inherits from IEnumerable but typically any LINQ to SQL generates T-SQL at the backend to be able to get the data for us. This evaluate and generates the query at one shot and gives us the whole data.
What is the difference between IQueryable<T> and IEnumerable<T>?

- 1
- 1

- 5,900
- 11
- 57
- 82
IEnumerable means I can return items of T.
IQueryable means I can return items of T but I can also accept LINQ operations (Where, Select etc) that I will process and translate to whatever is supplying data behind the scenes.
Now of course IEnumerable looks like it also accepts LINQ operations but the difference is they are never translated and are instead just executed in-memory. e.g. the Where operator just does something like this:
T Where(IEnumerable values, Func predicate) { foreach(var value in values) if (predicate(value)) yield return value; }

- 6,575
- 27
- 43