Difference between IEnumerable and IQueryable in c#

Difference between IEnumerable and IQueryable in c#

The biggest difference between them is all about where the filter logic gets executes. incase of IEnumerable filter logic gets executed at the client-side. incase of IQueryable filter logic gets executed at the database side by using SQL.

  •  Both IEnumerable and IQueryable are interfaces to dot net collection. 
  • IQueryable interface inherits IEnumerable (simple we can say whatever the things IEnumerable can do IQueryable also can do ).
  • But there are some things that IQueryable can do but IEnumerable will not be able to do it.
  • But one big difference is where the filter logic gets to execute. 
  • IQueryable good compare to IEnumerable 
  • if you don't use in-memory collection then go for IQueryable 
So As a practice, if you are working in-memory data collections. which means that collection no connection with RDBMS then it is better than using the IEnumerable.
But if you work with a collection which connected to the database then IQueryable is a good choice.

  • If you use IQueryable then it reduces the network traffic.




Previous Post Next Post