I'm looking for confirmation/clarification with these LINQ expressions:
var context = new SomeCustomDbContext()
// LINQ to Entities?
var items = context.CustomItems.OrderBy(i => i.Property).ToList();
// LINQ to Objects?
var items2 = context.CustomItems.ToList().OrderBy(i => i.Property);
Am I correct in thinking the first method is
LINQ to Entities
where EF builds a more specific SQL statement to pass on, putting the ordering effort on on the database?Is the second method
LINQ to Objects
where LINQ drags the whole collection into memory (theToList()
enumeration?) before ordering thus leaving the burden on the server side (the web server in this case)?If this is the case, I can quickly see situations where L2E would be advantageous (ex. filtering/trimming collections before pulling them into memory).
But are there any other details/trade-offs I should be aware of, or times when "method 2" might be advantageous over the first method?
UPDATE:
Let's say we are not using EntityFramework, this is still true so long as the underlying repository/data source implements IQueryable<T>
right? And if it doesn't both these statements result in LINQ to Objects
operations in memory?