GETTING STARTED WITH LINQ:
As data plays a vital role in almost every application development therefore LINQ was provided as a whole new way to manipulate data, either to or from database, or with XML file or with simple list of dynamic data.
LINQ stands for "Language Integrated Query",It is self explanatory as the Language Integrated part means that LINQ is part of programming language syntax as it can be integrated with it.The other part 'Query', explains what LINQ does, It is used for querying data such as, relational, XML, and even objects.
NOTE:(As LINQ can be used in many ways such as, LINQ to SQl, LINQ to XML, LINQ to Objects, etc. therefore we will discuss them one by one in later blogs).
In other words we can say that it is a programming language syntax that is used to query data.
Example:
var result = from c in Customers
where c.City == "India"
select new { c.FirstName, c.LastName, c.Address };
The above query has three clauses: from, where, and select. The from clause has a range variable, c, which holds an individual reference for each object of the data source, result.
The where clause filters the result, returning only object who's City = 'India'. The select clause returns the part of the object we want to return, referred to as a projection, In the above example we have returned FirstName,LastName & Address of the object where City = 'India' .
LINQ v/s ADO.NET:
Following are some points that differ LINQ from ADO.Net:
1. ADO.Net was introduced in .NET Framework since .NET Framework 1.0,
Whereas
LINQ was introduced since NET Framework 3.5.
2. ADO.Net is difficult to debug and cause syntax errors at run-time,
Whereas
LINQ is easy to debug and cause syntax errors at compile-time.
3. ADO.Net is used in T-SQL to query the database,
Whereas
LINQ is used in .NET Framework languages like C# and VB.
4. ADO.Net provides full type checking at run-time and do not have IntelliSense support in Visual Studio,
Whereas
LINQ provides full type checking at compile-time and IntelliSense support in Visual Studio.
5. ADO.Net provides T-SQL and some other syntax to query the database and for querying the
other data source,
Whereas
LINQ provides the uniform programming model to query the various data sources.
0 Comment(s)