Confusion! AsEnumerable() execute the SQL Query

I got asked number of Software Developer in the team about this question, especially when you use LINQ to query the database. Using ToList() directly from DbTable or Repository is the first thing that I tell all new developer to avoid as it will get all the records of database and put to in-memory objects, it will ether time out or has very terrible performance.

However, you can still use AsEnumerable as an extension method to filter or take number of records which IQueryable doesn’t have because AsEnumeriable doesn’t execute SQL query until we use ToList() or FirstOrDefault() etc.

It’s a good tip, especially for those who are new to LINQ.