Language-Integrated Query (LINQ) is a set of features introduced in Visual Studio 2008 that extends powerful query capabilities to the language syntax of C# and Visual Basic. LINQ introduces standard, easily-learned patterns for querying and updating data, and the technology can be extended to support potentially any kind of data store. Visual Studio includes LINQ provider assemblies that enable the use of LINQ with .NET Framework collections, SQL Server databases, ADO.NET Datasets, and XML documents.
You can use Language-Integrated Query (LINQ) in Web pages to retrieve and modify data. LINQ applies the principles of object-oriented programming to relational data. It provides a unified programming model for querying data from different types of data sources, and extends data capabilities directly into the C# and Visual Basic languages.
You can use LINQ through the LinqDataSource control, through the ObjectDataSource control, or by creating LINQ queries.
The LinqDataSource control provides an easy way to connect to data from a database or to an in-memory data collection such as an array. You can declaratively write all the conditions that are required for typical scenarios such as retrieving, filtering, ordering, and grouping the data. The control dynamically creates the LINQ queries from the values that you provide declaratively.
To display the data in a Web page, you bind a data-bound control to the LinqDataSource control. Examples of data-bound controls are the GridView or DetailsView controls.
You use the ObjectDataSource control when you want to interact with the data in a more complex way than is possible with the LinqDataSource control. For example, you can create an update method that includes setting values in joined tables.
You can use the ObjectDataSource control with a LINQ to SQL class. To do so, you set the TypeName property to the name of the data-context class. You also set the SelectMethod, UpdateMethod, InsertMethod, and DeleteMethod methods to the methods in the data-context class that perform the corresponding operations.
You can include LINQ queries in a Web page without using a data source control. You might use a LINQ query if you need to use a query operator that is not available in the LinqDataSource control. You might also use it if you want to display read-only data in a data-bound control without the processing that is required to create a data source control.