What’s the difference between IQueryable and IEnumerable [duplicate]

IEnumerable<T> represents a forward-only cursor of T. .NET 3.5 added extension methods that included the LINQ standard query operators like Where and First, with any operators that require predicates or anonymous functions taking Func<T>. IQueryable<T> implements the same LINQ standard query operators, but accepts Expression<Func<T>> for predicates and anonymous functions. Expression<T> is a compiled expression … Read more

Using IQueryable with Linq

Marc Gravell’s answer is very complete, but I thought I’d add something about this from the user’s point of view, as well… The main difference, from a user’s perspective, is that, when you use IQueryable<T> (with a provider that supports things correctly), you can save a lot of resources. For example, if you’re working against … Read more

How to mock the limitations of EntityFramework’s implementation of IQueryable

I think it is very very hard, if impossible, to mock Entity Framework behaviour. First and foremost because it would require profound knowledge of all peculiarities and edge cases where linq-to-entites differs from linq-to-objects. As you say: the real challenge is finding them. Let me point out three main areas without claiming to be even … Read more

What is the difference between IQueryable and IEnumerable?

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<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. What IQueryable<T> has that IEnumerable<T> doesn’t … Read more

Returning IEnumerable vs. IQueryable

Yes, both will give you deferred execution. The difference is that IQueryable<T> is the interface that allows LINQ-to-SQL (LINQ.-to-anything really) to work. So if you further refine your query on an IQueryable<T>, that query will be executed in the database, if possible. For the IEnumerable<T> case, it will be LINQ-to-object, meaning that all objects matching … Read more