As far as I understand, IQueryable is a query that has not been executed yet, and the filter conditions like .Where(x=> x != 3)
are added to the SQL query and get the final result when executed. IEnumerable, on the other hand, first takes all the data and puts it into the memory, the filtering is done over all the data in the memory.
- If IEnumerable takes the data and puts it into memory, is the query executed?
- So why is it said to be executed when using methods like
.Count()
if the IEnumerable has already run and dumped the data into memory? - Why do we do
.Count()
and not.Count
like List type?
public IEnumerable<Number> GetNumbers()
{
IQueryable<Number> result = _context
.Numbers
.Where(x => x != 3);
return result;
}
- In the above code, the
result
is of type IQueryable, but IEnumerable returned from the method. What kind of operation takes place here, while a query that hasn't been executed yet, is the query executed and thrown into memory when the return statement is executed?