What is the difference between returning IQueryable
vs. IEnumerable
, when should one be preferred over the other?
Both will give you deferred execution, yes.
As for which is preferred over the other, it depends on what your underlying datasource is.
Returning an IEnumerable
will automatically force the runtime to use LINQ to Objects to query your collection.
Returning an IQueryable
(which implements IEnumerable
, by the way) provides the extra functionality to translate your query into something that might perform better on the underlying source (LINQ to SQL, LINQ to XML, etc.).