LINQ is an abbreviation of Language Integrated Query and it is a collection of standard query operators developed by Microsoft that provides the query facilities into .NET framework language like C#, VB.NET. It helps in a compact and intelligible way for manipulating data. There are various type of LINQ e.g. LINQ to Objects, LINQ to XML, LINQ to Dataset, LINQ to SQL and LINQ to Entities.
Stored procedures are faster in execution than LINQ and the reason for that is they have a full predictable(cache) execution plan & they also have the benefit of SQL features. If any stored procedure is executed for the second time, the database simply has the cached execution plan to execute it. LINQ emphasises on type safety more as compared to stored procedures hence query errors are type checked at the time of compilation itself rather than at the runtime. LINQ supports abstraction hence it can add multi threading. LINQ has debugging feature using .NET debugger.
Yes, we can use LINQ with databases other than SQL Server too. It can be done through LINQ to Objects or LINQ to Datasets. In this case, the objects and datasets will take care of all the operations related to database and LINQ will deal with those objects directly and not the database operations.
Standard Query Operators, Language Extensions and LINQ Providers.
LINQ has following advantages
A Lambda expression is a function which can be used to create expressions and statements. It is used to represent anonymous method using specific syntax. It uses lambda operator => and read as 'goes to' operator. % An example of it is a=>a*a%
For constructing expression trees Expression Lambda is used but we cannot use Statement Lambda for this purpose. Further, statement lambda is not supported by expression providers like LINQ to SQL.
DataContext class can be explained as a bridge between a SQL Server database and the LINQ to SQL. It establishes connection to database for accessing the database. Communicate with database by submitting and retrieving objects and then change these objects to SQL queries. In a simpler way, it contains the connection string information, methods to connect to the database and manipulating the data in the database. With the help of data context, we can perform select, insert, update and delete operations over the data in the database.
Both XElement and XDocument are the classes defined by System.Xml.Linq namespace. XElement class represents an XML fragment. XDocument class represents an entire XML document with all associated meta-data. XDocument has a Declaration i.e. root whereas XElement is a single node.
For loading everything under the top-level element, we have to use XElement.Load () and for loading any markup before the top-level element, we have to use XDocument.Load ().