Chris_Conn
(Chris Conn)
September 17, 2017, 3:12am
1
I know this isn’t stack overflow but I figured since we are in the same world of LINQ, SQL and DBs I would pose this question.
What are the fundamental differences between the following bits of code? Do they both have deferred datasource access?
var numQuery =
numbers.Where(num => num % 2 == 0);
vs
var numQuery =
from num in numbers
where (num % 2) == 0
select num;
@josecgomez come on, be my Jon Skeet
josecgomez
(Jose C Gomez)
September 17, 2017, 5:50pm
2
There is no practical difference. One is just a lambda implementation
Jos? C Gomez
Senior Software Engineer
1 Like
josecgomez
(Jose C Gomez)
September 17, 2017, 5:51pm
3
Jos? C Gomez
Senior Software Engineer
danbedwards
(Dan Edwards)
September 18, 2017, 12:31pm
4
@Chris_Conn yes, they are both deferred execution. For immediate execution a query would be something like below or the use of an immediate operator (count, sum, etc.). The deferred execution is the better way to go for performance.
var emp = Employees.Where(x => x.Salary < 35000)
.Select(y => y.Name).ToList();
2 Likes