IQueryable or IEnumerable?

Questions about .NET framework
Post Reply
AndreyV
Posts: 1
Joined: Mon Oct 09, 2017 8:31 am

IQueryable or IEnumerable?

Post by AndreyV » 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?

SergeyZ
Posts: 3
Joined: Mon Oct 16, 2017 6:46 am

Re: IQueryable or IEnumerable?

Post by SergeyZ » 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.

Post Reply