---
title: "Difference between IQueryable<T> vs IEnumerable<T>"  
description: "A lots of time Confusion between IQueryable and IEnumerable interface because, they are look like same and when we start writing a code often,we will"  
author: "Anupam Mishra"  
published: 2016-03-25  
updated: 2018-03-14  
canonical: https://www.mindstick.com/blog/11030/difference-between-iqueryable-t-vs-ienumerable-t  
category: "asp.net mvc"  
tags: ["c#", "asp.net", "asp.net mvc", "interface"]  
reading_time: 3 minutes  

---

# Difference between IQueryable<T> vs IEnumerable<T>

A lots of time Confusion between **IQueryable and IEnumerable** interface because, they are look like same and when we start writing a code often, we will choose a wrong approach between them. From behind this reason was I am unable to know perfectly about these two. Here, we will try to explain a differences.

IQueryable interface:

IQueryable exists in System.Linq Namespace. It only forward only over a collection. This is a better query data from out-memory (like [remote database](https://www.mindstick.com/articles/12843/reasons-why-hiring-remote-database-consulting-services-is-the-hottest-industry-trend), service) collections. When we access a data from a database IQueryable execute select query on server side with all filters. It support [Lazy Loading](https://www.mindstick.com/articles/324873/lazy-loading-in-entity-framework) that was better for paging.

IQueryable<T> is the interface that allows LINQ-to-SQL to work. If we want to refine another query it will executes, [if necessary](https://www.mindstick.com/forum/23229/in-python-check-if-a-directory-exists-and-create-it-if-necessary).

##### In code:

IQueryable<Student> stud = ………….\
var studentGrade = db.Students.stud .Where(x =>x.grade<5);

That code will execute SQL to only select Students which grade is <5. And

\

we have also filter all other students which grade above from 5.

##### IEnumerable interface:

\

Enumerable exists in System.Collections Namespace. It only forward only over a collection. IEnumerable is best to query data from in-memory collections. While we access [data from database](https://www.mindstick.com/forum/34370/how-to-populate-google-charts-using-data-from-database-created-via-data-first-asp-dot-net-mvc), IEnumerable interface execute [select query](https://www.mindstick.com/articles/1858/sqlite-select-query) on [server side](https://www.mindstick.com/forum/318/how-to-call-javascript-fuction-in-server-side) and load data in-memory on [client side](https://www.mindstick.com/forum/160418/what-are-the-best-practices-for-securely-storing-bearer-tokens-on-the-client-side) and then [filtering data](https://www.mindstick.com/forum/160900/how-to-use-searching-and-filtering-data-in-an-sql-server). IEnumerable is suitable for LINQ to Object queries. IEnumerable supports deferred execution. IEnumerable does not support custom query and also be a lazy loading.

**IEnumerable<T>** is the **interface that allows LINQ-to-Object to work**. It means that all objects matching the original query will have to be [loaded into memory](https://www.mindstick.com/interview/2404/an-app-is-loaded-into-memory-but-is-not-executing-any-code-in-which-state-will-it-be-in) from the database.

\

**IEnumerable<Student> stud = ……….\** **var studentGrade = db.Students.stud .Where(x =>x.grade<5);**

This is quite an important difference, and working on **IQueryable<T>** can in many cases save you from returning too many rows from the database. Another prime example is doing paging: If you use **Take** and**Skip** on IQueryable, you will only get the number of rows requested; doing that on an **IEnumerable<T>** will cause all of your rows to be loaded in memory.

##### Differences:

There are many differences as below:

IEnumerable:

**1**. IEnumerable is exists under the System.Collections namespace.

**2.** IEnumerable is suitable for querying data from in-memory collections.

**3.** While querying [data from the database](https://www.mindstick.com/forum/160510/how-to-fetch-data-from-the-database-in-the-dot-net-console-application-using-c-sharp), IEnumerable executes "select query" on the server-side, loads data in-memory on the client-side and then filters the data.

**4.** IEnumerable is also be better work for LINQ to Object and LINQ to XML queries.

##### IQueryable:

##### 1. IQueryable is exists under the System.Linq Namespace.

##### 2. IQueryable is suitable for querying data from out-memory (like remote

##### database, service) collections.

##### 3. While querying data from a database, IQueryable executes a "select

##### query" on server-side with all filters.

##### 4. IQueryable is beneficial for LINQ to SQL queries.

---

Original Source: https://www.mindstick.com/blog/11030/difference-between-iqueryable-t-vs-ienumerable-t

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
