Calling AsEnumerable(
) does not execute the query, enumerating it does.
IQueryable
is the interface that allows LINQ to SQL
to perform its magic. IQueryable
implements IEnumerable
so when you call AsEnumerable()
, you are changing the extension-methods being called from there on, ie from the IQueryable
-methods to the IEnumerable
-methods (ie changing from LINQ to SQL
to LINQ to Objects
in this particular case). But you are not executing the actual query, just changing how it is going to be executed in its entirety.
To force query execution, you must call ToList()
.