Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why didn't the LINQ designers stick with using the way sql is written today?

Tags:

linq

For example, why do you do this in LINQ

var products = from p in Products
               select p.Name;

when they could have done this:

var products = select p.Name from Products p;

Does the second offer some limitations in linq? Maybe the above examples are too simple to actually see why linq is written in one order and sql is written in another.

like image 768
Xaisoft Avatar asked Oct 02 '09 12:10

Xaisoft


People also ask

How does LINQ work SQL?

When the application runs, LINQ to SQL translates into SQL the language-integrated queries in the object model and sends them to the database for execution. When the database returns the results, LINQ to SQL translates them back to objects that you can work with in your own programming language.

When should we use LINQ?

LINQ in C# is used to work with data access from sources such as objects, data sets, SQL Server, and XML. LINQ stands for Language Integrated Query. LINQ is a data querying API with SQL like query syntaxes. LINQ provides functions to query cached data from all kinds of data sources.

What is LINQ query operators?

A set of extension methods forming a query pattern is known as LINQ Standard Query Operators. As building blocks of LINQ query expressions, these operators offer a range of query capabilities like filtering, sorting, projection, aggregation, etc.


2 Answers

Because LINQ is not SQL. LINQ consists of a number of chained extension methods on IEnumerable<T> (when you are using the System.Linq namespace). The SQL like syntax is just a compiler trick to enable some syntactic sugar on chains of such query methods so it appears you can use queries looking a bit like SQL inside .NET languages. LINQ basically has nothing to do with SQL per se...

like image 57
peSHIr Avatar answered Sep 19 '22 23:09

peSHIr


Because in order to have Intellisense in Visual Studio working with LINQ, it needs to know the tables first so that the editor can offer the programmer the list of columns to choose from. If you do it the SQL way and first you choose the columns, the editor can't really help you as it doesn't know which tables to look at.

like image 31
Tamas Czinege Avatar answered Sep 16 '22 23:09

Tamas Czinege