No, that doesn't return all the values before filtering. The Take(100)
will end up being part of the SQL sent up - quite possibly using TOP.
Of course, it makes more sense to do that when you've specified an orderby
clause.
LINQ doesn't execute the query when it reaches the end of your query expression. It only sends up any SQL when either you call an aggregation operator (e.g. Count
or Any
) or you start iterating through the results. Even calling Take
doesn't actually execute the query - you might want to put more filtering on it afterwards, for instance, which could end up being part of the query.
When you start iterating over the results (typically with foreach
) - that's when the SQL will actually be sent to the database.
(I think your where
clause is a bit broken, by the way. If you've got problems with your real code it would help to see code as close to reality as possible.)