Problem
Consider:
ContextSet().Select(x=> x.FirstName == "John") // A
ContextSet().Where(x=> x.FirstName == "John") // B
When should I use .Select vs .Where?
- Select is a projection, so what you get is the expression
x=> x.FirstName == "John"
evaluated for each element in ContextSet() on the server. i.e. lots of true/false values (the same number as your original list). If you look the select will return something likeIEnumerable<bool>
(because the type ofx=> x.FirstName == "John"
is a bool). UseSelect
when you want to keep all results, but change their type (project them). - Where filters the results, returning an enumerable of the original type (no projection). Use
Where
when you want to filter your results, keeping the original type