Have been reading questions & answers, articles, they all say:
By using IEnumerable<T>, it fetches all data from the database to your application's memory and then applies filters on top of it (this is unacceptable for my project); whereas IQueryable<T> is the saviour: it does the filtering in the database and then returns only the filtered data into memory.
In my ASP.NET Core with Kestrel project, I can see how the lambda expression or LINQ is translated into SQL commands (from the Kestrel console) and I have tried in my code to use both of them, but the translated SQL query looks the same:
Can anyone enlighten me how to see the differences please?
Update
Here is the code:
public IQueryable<Apartment> GetApartmentsByPostcode(string postcode, int pageIndex, int pageSize)
{
return _dataContext.Apartment
.Include(a => a.ApartmentDetails)
.Where(a => string.Compare(a.PostCode, postcode, true) == 0 && a.Enabled == true)
?.Skip((pageIndex - 1) * countPerPage)
?.Take(30);
}
I switched between IQueryable and IEnumerable (.AsEnumerable() at the end of the Take(30))
I know Take(), Skip, Where etc. will return IQueryable, but there is no way to make them to return IEnumerable from the root.
So may I conclude it does not matter to use IQueryable or IEnumerable as return type?
