In SQL queries 'Select' comes first, then comes 'From', but in LINQ, we have to write 'From' fist and 'Select' later. Why is it so?
Nilesh Shah
Because in SQL server we know that we are querying on existing sql data source(a table or view) but in LINQ , we dont know upfront which data source we are writing a query, it might be an object,sql data source or xml document. So, we need to specify the source we are querying first. Also, specifying the source first, the visual studio can provide the intellisense to the following 'select' statment.
LINQ is based on C# which is a declarative language, means whenever you want to use any variable name, it must have been already been declared beforehand. In LINQ queries, when you write "From" first - it declares the variable whoch can later be used in "Select" statement.