In Entity Framework, what is the difference between Select and Where?

.net c# entity-framework linq linq-to-sql

Question

What distinguishes the two.Select() and .Where() using Entity Framework?

return ContextSet().Select(x=> x.FirstName == "John")

vs

ContextSet().Where(x=> x.FirstName == "John")

When ought I to employ.Select vs .Where ?

1
51
12/20/2011 4:09:48 PM

Accepted Answer

The result is the expression because Select is a projection.x=> x.FirstName == "John" assessed for each component inContextSet() inside the server. many true/false values, etc (the same number as your original list). The select will return something like if you look.IEnumerable<bool> (Due to the kind ofx=> x.FirstName == "John" a bool).

The filtering function Where returns an enumerable of the original type (no projection).


So, utilizeSelect when you want to modify the kind of the results while keeping the rest (project them).

Use Where When filtering your results, keep the original kind in mind

82
11/22/2011 4:42:25 PM

Popular Answer

Where() the filter.

Select() chooses a different piece of information.
Your Select() A collection of booleans will be returned by example.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow