What is IEnumerable, ICollection, IList, and IQueryable

Çağlar Can SARIKAYA
.Net Programming
Published in
3 min readDec 27, 2021
A funny Queue :)

Hi guys, I am always using that all, but I wasn't know what is exactly until a couple of days ago :)

Firstly let's separate these, queryable is, on the one hand, others in another hand. One is works as in database come from System.Linq and other is works in memory come from System.Collections.Generic.

Let’s assume you have 5000 records on your product table. When you create a query using LINQ,

_someRepository.GetAll();

it will respond as an IQueryable object with your all records. It creates a query like

SELECT *
FROM Product

You can filter this data on the database side

_someRepository.GetAll().Where(x => x.Name.Contains("can"));

it will respond as an IQueryable object with your all records. It creates a query like

SELECT *
FROM Product
WHERE Name like '%can%'

then you will achieve you IQueryable data, it means you get it from the database, until putting into a list.

var AllProduct = _someRepository.GetAll().ToList();

When you do that you will cast this to list which comes from Enumerable, you put that data on your ram.

Linq Library

IQueryable is database side and comes from linq, others are ram side comes from Collections. The first object type is enumerable which you can store on your ram.

IEnumerable from Collections

Enumerable is a basic one, you cant manipulate the data, you cant remove one of them, you cant add, you can't replace, or you don't know how much there, But one thing you can do it, a basic loop. It is an enumerator, it has only 2 methods move next and reset.

If you go one stair up, you will see the collections. Which comes from ICollection, and is based on IEnumerable. As you can see the bottom picture, derived from IEnumerable

ICollection from Collections

There are basic methods but enough for many thing, also you know the count :)

--

--