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.
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.
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.
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.
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...
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With