Click here to Skip to main content
Click here to Skip to main content

Tagged as

IEnumerable  Vs IQueryable

, 24 Feb 2014
Rate this:
Please Sign up or sign in to vote.
Many  developers gets confused between IEnumerable and IQueryable. When it comes to writing code, both looks very similar. However there are many difference between them which needs to be taken care of while writing code. Both have some intended usability scenarios for which they are made. Below lis

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

Below lists 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 execute 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 execute 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 supports. Supports using CreateQuery and Execute methods.
Extension mehtod
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

 

License

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

Share

About the Author

Adarsh Chaurasia (Consultant|Mentor|Tech Savvy)
Software Developer (Senior)
India India
I have 4.6+ years of experience in SaaS, SOA based Enterprise Web Application design and development using Microsoft technology stack. I have mostly worked on Business layer, Data access layer, WCF, Entity Framework, Microsoft Application Blocks, Search engines, APIs integration, Third party APIs/Product Research & Development.
 
I am a huge fan of Design Patterns. I also work as Software Consultant. I read/write blogs, help and learn from other developers.
Follow on   Twitter   LinkedIn

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web02 | 2.8.140821.2 | Last Updated 24 Feb 2014
Article Copyright 2014 by Adarsh Chaurasia (Consultant|Mentor|Tech Savvy)
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid