query.ToList()
is the same like myContext.MyTable.ToList()
. It returns a collection in memory (the whole database table) and is just an IEnumerable<T>
, not an IQueryable<T>
. Every further LINQ operator - for example a Where
clause - you append, will be performed in memory and not in the database.
If you choose to return IEnumerable<T>
or List<T>
from your repository you have to design the repository methods so that you can apply filters, sorting, etc. inside of those methods - for example by passing in filter and sort expressions as parameters into the methods or by creating lots of specialized methods for different use cases - like GetOrdersByCustomerId
, GetOrdersByShippingDate
, etc., etc. If you do it outside of and after calling repository methods you will suffer from poor performance.