I have a big question that has been puzzling me for a long time and that I can’t seem to get a straight answer for anywhere and I am sure that if someone can answer this with authority and with good examples that it will help not only me but thousands of developers to come. All I want to know is what are the characteristics of the following concepts and what are the differences between them
Linq
Linq to SQL
Linq to Entities
Linq to Objects
Lambda expressions
Also, in particular, can someone tell us where constructs such as these fall into the above categories
Construct 1
var result = from n in nums
where n < 5
orderby n
select n;
Construct 2
Entities.Person.Where(p => p.FirstName == "John").First();
Your learned clarifications are eagerly awaited.
I’m sure there are some over-simplifications here, but for what it’s worth:
Linq is an API designed for dealing with data sets.
IQueryable, for instance, comes from theSystem.Linqnamespace. Linq to … are different implementations that parse the same Linq instructions to perform different operations based on how your data is stored. So Linq to SQL will parse your.Whereinstruction to produce a sql query with aWHEREclause, while Linq to Objects would take that same instruction and produce aforeach.A lambda expression is pretty much a shorthand for an anonymous delegate. You identify a lambda by the
=>operator. Your argument list is at the left hand of the=>and the expression that can access those arguments and optionally return a result is at the right hand.Your two code examples are different syntaxes in which Linq queries can be written. They are called Query syntax and Method syntax, respectively.