In this article I will demonstrate how to write code via IEnumerable and IQueryable and what the differences are between them.
IEnumerable and IQueryable are used for data manipulation in LINQ from the database and collections.
For getting the data from the database, I have created a table named "Employee" that has some data and looks like:

Then creating the Data Context class (.dbml class) in your project that converts the database table named "Employee" as a class.
Now I will tell you the functionality and some basic differences between IEnumerable and IQueryable using the object of the Data Context class..
IEnumerable Code

SQL statement after execution of above query
After the execution of line number 18, the SQL statement will look like the following until the end:

IQueryable Code

SQL statement after execution of the preceding query
After the execution of line number 22, the SQL statement will look like:

But after the execution of line number 23, SQL statement will add the Top for the filtering.

In both syntaxes I am accessing the data from the Employee table and then taking only 3 rows from that data.
Differences
IEnumerable
- IEnumerable exists in the System.Collections namespace.

- IEnumerable is suitable for querying data from in-memory collections like List, Array and so on.
- While querying data from the database, IEnumerable executes "select query" on the server-side, loads data in-memory on the client-side and then filters the data.

- IEnumerable is beneficial for LINQ to Object and LINQ to XML queries.
IQueryable
- IQueryable exists in the System.Linq Namespace.

- IQueryable is suitable for querying data from out-memory (like remote database, service) collections.
- While querying data from a database, IQueryable executes a "select query" on server-side with all filters.
- IQueryable is beneficial for LINQ to SQL queries.


Bahman ShafieiPosted Apr 4, 2024, 2:34 AM EDT
Unfortunately this article was not clear for me.
Ammar ShaukatPosted Jul 1, 2022, 7:45 AM EDT
Thanks @Rahul Bansal for explaining this in such an easy way..
Sudheshwer RaiPosted Oct 23, 2021, 12:25 PM EDT
I don't know how C# Corner Approved this article. There is multiple error and still this article is running. Man, please correct it.
Muhammad Shahid Khan AfridiPosted Jul 12, 2021, 10:50 PM EDT
Lots of mistakes were found in this article, you should review it again and make some changes so that it will provide useful information to newbies.
Naresh KumarPosted May 26, 2021, 5:05 AM EDT
Correct the article please
Roshan RathodPosted Jul 23, 2020, 12:25 AM EDT
Good article..keep it up sir
Hemant SoniPosted Apr 5, 2020, 5:11 PM EDT
In statement "After the execution of line number 18", where is Lin 18?? and at the time of explaining "IEnumerable Code" used IQuriable, Please check code and correct that.
Sujeet SinghPosted Feb 18, 2020, 7:51 PM EST
"After the execution of line number 18" where is Lin 18??
Kumaresan MurugesanPosted Aug 11, 2019, 12:57 AM EDT
Nice Article
Ozmen GokPosted Jan 22, 2019, 7:13 AM EST
It is Very clear explanation, I want to add a thing only, to clearify , when you refer server side on "While querying data from a database, IQueryable executes a "select query" on server-side with all filters." , you mention about DATABASE and "While querying data from the database, IEnumerable executes "select query" on the server-side, loads data in-memory on the client-side " here server side still refers DATABASE and client side refers IN MEMORY(execution our CSHARP code), AM I TRUE?
Micro techiePosted Jan 7, 2019, 10:33 PM EST
Very straight forward explanation thank you very much
Brijesh MavaniPosted Dec 6, 2018, 7:55 PM EST
Performance wise which one is good?
neeraj kanojiyaPosted Nov 22, 2018, 8:19 PM EST
Very good example given.
jubula samalPosted Nov 15, 2018, 7:34 PM EST
Explained superbly
Navjyot YadavPosted Nov 13, 2018, 6:27 AM EST
Performance wise which one is more preferred?
Stephen DevasyPosted Nov 6, 2018, 11:37 PM EST
Thanks sir very easy to understand
Dinesh Kumar SharmaPosted Aug 28, 2018, 2:48 AM EDT
Thank Sir very nice article
Razat KumarPosted Aug 5, 2018, 11:57 PM EDT
Thanks, very nice article
Shakir AliPosted May 31, 2018, 11:03 AM EDT
Very Nice explanation....
Istekhar AhmadPosted Mar 30, 2018, 3:19 AM EDT
Nice one explain clearly.
Dennis ThomasPosted Mar 5, 2018, 8:56 PM EST
Good explanation Rahul. Thanks!
shruti patilPosted Mar 1, 2018, 5:38 PM EST
Clearly explained,thank you!
MaharajaPosted Sep 21, 2017, 11:26 PM EDT
Understood . Thanks
zul ismailPosted Aug 7, 2017, 2:18 AM EDT
Very clear explanation, thanks.
RonakPosted Sep 23, 2016, 10:13 PM EDT
Good article with explanation. Thanks
gowtham vPosted Oct 11, 2015, 8:33 PM EDT
Thank you