IEnumerable runs LINQ operators in memory over objects that are already loaded. IQueryable builds an expression tree that a provider such as EF Core translates into SQL, so filters and projections run in the database. Both are deferred until enumerated. Switching to IEnumerable too early, for example by calling AsEnumerable or ToList before a Where, pulls the whole table into memory and filters it there.
Why interviewers ask this
This distinction decides whether a query fetches ten rows or ten million, and it is one of the most common performance mistakes in EF Core code. The interviewer wants expression trees versus delegates, deferred execution, and the point at which a query actually reaches the database. Spotting multiple enumeration, where the same query quietly runs several times, shows you have reviewed real code rather than only written it.
How to structure your answer
- Define each by where the work happens.
- Explain expression trees and provider translation.
- Cover deferred execution and when the query actually runs.
- Give the common mistakes: early materialisation and repeated enumeration.
Example answer
The difference is where the work happens. IEnumerable works on objects in memory, running each operator as a delegate in my process. IQueryable builds an expression tree describing the query, and the provider, EF Core here, translates that tree into SQL when the query executes. So a Where on an IQueryable becomes a WHERE clause in the database, while the same Where on an IEnumerable means the rows were already fetched and I am filtering in memory. Both are deferred, so nothing runs until I enumerate. The bug I see most is materialising too early. Someone writes a repository method returning IEnumerable, or calls ToList and then filters, and the whole table comes back to be filtered in the app. It works perfectly in development with fifty rows and falls over in production. The other is multiple enumeration: passing an unmaterialised query around and calling Count and then foreach, which runs it twice. I keep queries as IQueryable inside the data layer and materialise once, deliberately, selecting only the columns I need.
Walking into this interview soon? GhostPilot listens to your live call, spots the question the moment it is asked, and puts a structured answer on your screen in real time. Try it on your next mock, or grab a $29 Session Pass, no subscription, for the real thing.
See how it worksFollow-up questions to expect
- What happens when EF Core cannot translate part of a query to SQL?
- Should a repository return IQueryable to its callers?
- How would you spot a query being executed more than once?
Related .net developer questions
Your interviewer will ask their own version of this. Paste your actual job description into the free Question Predictor and get the 20 questions that role is most likely to ask, with what each one is really probing.
Predict my questions