tags:

views:

30

answers:

1

Hi All,

I'm trying to figure out the difference between Where(Expression) and Single(Expression).

Is the Expression passed into single forwarded to a Where function?

eg, are these two statements the same?

var result = context.Persons.Single(p => p.ID == 5);
var result2 = context.Persons.Where(p => p.ID == 5).Single();
+4  A: 

Single returns you a Person, whereas the Where will return you an IEnumerable<Person>.

Passing the where expression into the single is just syntactic sugar.

Both the lines are functionally equivalent. The first I imagine could be ever so marginally more efficient. It's also easier on the eye in my opinion.

danielfishr