views:

41

answers:

1

if you have something like(just an example don't worry)

var result = from n in mytable select n;
var last = n.LastOrDefault;
var secondresult = n.FirstOrDefault;
var Thirdresult = secondresult.FirstOrDefault;
var Finalresult = Thirdresult.FirstOrDefault;

is this will query the database 5 times?

+1  A: 

That will query the DB at least twice, in the second two statements.

Possibly four times (though probably not, as the third and fourth statements don't really make sense as most elements of a returned L2E or L2S queryable are not themselves enumerable; since you don't show the types I'll leave the possibility open), depending on the types returned.

Not five times, as the first statement won't run a query.

Craig Stuntz
thanks, I'm currently reviewing some code done by other persons and I was seeing this kind of code everywhere and I wanted to make sure I was kind of right before telling them to fix it. I will wait 1 hour and if there is no better answer, you will get the green check
Fredou
To be sure, use SQL profiler.
Craig Stuntz