There are many topics on stackoverflow:
When should I use IEnumerable and when IQueryable?
What is the difference between IQueryable<T> and IEnumerable<T>?
When should I use IEnumerable and when IQueryable?
What’s the difference between IQueryable and IEnumerable
And everywhere people write that IEnumerable filters data from within memory while IQueryable does it on the server side. But this exacly isn’t true.
IEnumerable filters data from within memory ONLY if we split a query!!!
So:
IEnumerable<Customer> customers = context.Customers.Where(c => c.FirstName.StartsWith("J")).Take(5).ToList();
it gives a correct query with filter top(5):
select top(5) * from Customers WHERE FirstName like 'j%';
But:
IEnumerable<Customer> customers = context.Customers.Where(c => c.FirstName.StartsWith("J"));
var result = customers.Take(5).ToList(); //the filter is in a different line of code
it gives a query without top(5):
select * from Customers WHERE FirstName like 'j%';
So why people write that IEnumerable filters data from within memory while IQueryable does it on the server side?