Why LINQ?

With LINQ, you can use the same syntax to retrieve data from any data source:

var query = from e in employees
				where e.id == 1
				select e.name

This is not pseudocode; this is LINQ syntax, and it's very similar to SQL. The LINQ team's goal was not to add yet another way to access data, but to provide a native, integrated set of instructions to query any kind of data source. Using C# keywords, we can write data access code as part of C#, and the C# compiler will be able to enforce type safety and even logical consistency. LINQ provides a rich set of instructions to implement complex queries that support data aggregation, joins, sorting, and much more.

Figure 1 presents an overview of LINQ functionality. The top level shows the languages that provide native support for LINQ. Currently, only C# 3.0 and Visual Basic 9.0 offer complete support for LINQ.

The middle level represents the three main parts of the LINQ project:

LINQ to Objects is an API that provides methods that represent a set of standard query operators (SQOs) to retrieve data from any object whose class implements the
IEnumerable<T>
interface. These queries are performed against in-memory data.
LINQ to ADO.NET augments SQOs to work against relational data. It is composed of three parts (which appear at the bottom level of Figure 1): LINQ to SQL (formerly DLinq) is use to query relational databases such as Microsoft SQL Server. LINQ to
DataSet
supports queries by using ADO.NET data sets and data tables. LINQ to Entities is a Microsoft ORM solution, allowing developers to use Entities (an ADO.NET 3.0 feature) to declaratively specify the structure of business objects and use LINQ to query them.
LINQ to XML (formerly XLinq) not only augments SQOs but also includes a host of XML-specific features for XML document creation and queries.

Figure 1. Data domains in which LINQ adds functionality

NOTE

I don't cover LINQ to Entities because the ADO.NET Entity Framework is an ADO.NET 3.0 feature, and is not yet as mature as other technologies that can be used with LINQ.

Now let's see what you need to work with LINQ.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.220.96.214