views:

116

answers:

1

The following SQL

SELECT * FROM customers

converted to this in LINQ

var customers = from c in customers 
                select c;

Is their any good reasones why the from and select is swaped?

The only logical reason I can think of is for intellisens? For the intellesens to get resolved, it needs to know what it is querying (scope)?

Any other reasons why it was swaped?

+9  A: 

Select is swapped because it represents the order of the method calls that the LINQ query syntax is representing.

This is equivalent to

customers.Select(c=>c);

or

customers.Select();

SQL gets away with it, by processing the entire statement before proceeding, but in order to get things like intellisense and to figure out if your select is valid it has to be the last step and not the first.

You might also want to look at flowr, which is a closer representation, which stands for for, let, orderby, where, and return. You'll note the for, which is equivalent to from, is first; and the return, which is equivalent to select, is last.

SQL, here, is more the abnormality. How is one supposed to know what you're operating on before you've specified your domain.

Orion Adrian
In addition,it's interesting to note that, for obvious reasons, the new Intellisense feature in SQL 2008 Management Studio doesn't kick in until you have a FROM...
Codewerks