Accepted answer

linq isn't meant to be sql. it's meant to be a query language which is as independent of the data source as reasonably possible. now admittedly it has a strong sql bias, but it's not meant to just be embedding sql in source code (fortunately).

personally, i vastly prefer linq's syntax to sql's. in particular, the ordering is much more logical in linq. just by looking at the order of the query clauses, you can see the logical order in which the query is processed. you start with a data source, possibly do some filtering, ordering etc, and usually end with a projection or grouping. compare that with sql, where you start off saying which columns you're interested in, not even knowing what table you're talking about yet.

not only is linq more logical in that respect, but it allows tools to work with you better - if visual studio knows what data you're starting with, then when you start writing a select clause (for example) it can help you with intellisense. additionally, it allows the translation from linq query expressions into "dot notation" to be relatively simple using extension methods, without the compiler having to be aware of any details of what the query will actually do.

so from my point of view: no, linq would be a lot worse if it had slavishly followed sql's syntax.


the reason is the c# language designers use this approach because of when i first specify where the data is coming from, now visual studio and the c# compiler know what my data looks like. and i can have intellisense help in the rest of the query because visual studio will know that "city" (for example) is a string, and it has operations like startswith and a property named length. and really, inside of a relational database like sql server, the select clause that you are writing in a sql statement at the top is really one of the last pieces of the information the query engine has to figure out. before that it has to figure out what table you are working against in the from clause even though the from clause comes later in sql syntax


it is simpler to parse expression when initial data is provided in its beginning.

because of this vs provides code completion even for partially written linq queries (great feature imo).


first, choose your flavor of sql - there are several! (t-, pl-, etc).

ultimately, there are similarities and differences. a lot of the linq changes make more sense - i.e. choosing your source (from) before you try filtering (where) / projection (select), allowing better static analysis etc (including intellisense), and a more natural query comprehension syntax. this helps both the developer and the compiler, so i'm happy.

More Query from same tag