Page 1 of 1
IQueryable or IEnumerable?
Posted: Wed Oct 18, 2017 11:56 am
What is difference between IQueryable and IEnumerable interfaces when you working with database context?
When and why should I use one of them instead of another?
Does it depends on my DB request?
Re: IQueryable or IEnumerable?
Posted: Thu Oct 19, 2017 8:25 am
It is worth noting that IQueryable interface extends IEnumerable interface.
While querying data from database both interfaces execute select query on provider side. The difference is that IQueryable is able to execute filters on the provider side, which is especially useful with large amounts of data. IEnumerable loads data in-memory on client side and then work with that. Hence it becomes slow.
Whereas in specific cases, some transformations can not be performed on the provider side and navigating during Lazy loading can be torture. Hence in this case IEnumerable interface helps.