Question
.NET IEnumerable what is it exactly?
I'm trying to understand what an IEnumerable<>
is exactly.
I had thought it was just an interface saying the underlying data structure has these methods eg First()
etc.
However I have tested the the code shown here in EF which I would have expected to produce a TOP query in the DB as if it were running as an IQueryable
, but it instead causes it to pull the entire table in memory to perform its operation.
IEnumerable<EntityObject> m = DbContext.GetDbSet<EntityObject>();
var x = m.First();
So does treating something as an IEnumerable
force it into operating as an array or list or something?
Note I do NOT need to know how to optimize the query to be more performant, I am trying to understand why simply treating it as a different interface and using the same methods results in different underlying logic happening.