Click here to Skip to main content
15,879,239 members
Articles / All Topics

IEnumerable Vs IQueryable

Rate me:
Please Sign up or sign in to vote.
4.82/5 (103 votes)
24 Feb 2014CPOL1 min read 261.8K   49   13
IEnumerable Vs IQueryable

Many developers get confused between IEnumerable and IQueryable. When it comes to writing code, both look very similar. However, there are many differences between them which need to be taken care of while writing code. Both have some intended usability scenarios for which they are made.

Listed below are the differences between them based on their properties:

  IEnumerable IQueryable
Namespace System.Collections Namespace System.Linq Namespace
Derives from No base interface Derives from IEnumerable
Deferred Execution Supported Supported
Lazy Loading Not Supported Supported
How does it work While querying data from database, IEnumerable executes select query on server side, load data in-memory on client side and then filter data. Hence does more work and becomes slow. While querying data from database, IQueryable executes select query on server side with all filters. Hence does less work and becomes fast.
Suitable for LINQ to Object and LINQ to XML queries LINQ to SQL queries
Custom Query Doesn’t support Supports using CreateQuery and Execute methods
Extension method
parameter
Extension methods supported in IEnumerable takes functional objects. Extension methods supported in IEnumerable takes expression objects, i.e., expression tree.
When to use When querying data from in-memory collections like List, Array, etc. When querying data from out-memory (like remote database, service) collections.
Best Uses In-memory traversal Paging

This article was originally posted at http://synvistech.com/blogs/ienumerable-vs-iqueryable

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Comments and Discussions

 
QuestionThank you Pin
tripe3way13-Dec-19 1:35
tripe3way13-Dec-19 1:35 
PraiseGood effects Pin
hebsiboy22-Oct-16 19:12
hebsiboy22-Oct-16 19:12 
GeneralMy vote of 5 Pin
girishmeena28-Aug-16 4:54
girishmeena28-Aug-16 4:54 
QuestionIEnumerable Linq capabilities Pin
girishmeena28-Aug-16 4:52
girishmeena28-Aug-16 4:52 
QuestionThanks Pin
Pawan Tiwari9315-May-16 19:49
professionalPawan Tiwari9315-May-16 19:49 
Thanks a lot for making it clear in few words. Smile | :)
QuestionGood Short Descriptive Pin
Er. Puneet Goel6-Apr-16 0:46
professionalEr. Puneet Goel6-Apr-16 0:46 
GeneralGood Work Pin
Alireza_13623-Apr-16 8:21
Alireza_13623-Apr-16 8:21 
GeneralMy vote of 5 Pin
Chinh Vo Wili27-Jan-16 4:01
professionalChinh Vo Wili27-Jan-16 4:01 
GeneralRe: My vote of 5 Pin
Adarsh Chaurasia - Passionate Trainer22-Mar-16 5:58
professionalAdarsh Chaurasia - Passionate Trainer22-Mar-16 5:58 
Suggestiongood article Pin
toumir24-Nov-15 22:38
toumir24-Nov-15 22:38 
QuestionDifference between IEnumerable VS IQueryable:- Pin
Member 1057063910-Aug-15 18:23
Member 1057063910-Aug-15 18:23 
QuestionThank you Pin
Mahsa Hassankashi20-Sep-14 12:11
Mahsa Hassankashi20-Sep-14 12:11 
AnswerRe: Thank you Pin
Member 408341017-Jun-15 5:51
Member 408341017-Jun-15 5:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.