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.
When you retrieve data from a LINQ to SQL data context class, you can also configure a LinqDataSource control to handle update, insert, and delete operations. The control does this without requiring you to write the SQL commands to perform these tasks.
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.
The following example shows the markup for a LinqDataSource control that connects to the AdventureWorks database. It returns records from the Contact table that have a value in the EmailPromotion property equal to 1.
|
<asp:LinqDataSource
ContextTypeName="AdventureWorksDataContext"
TableName="Contacts"
Where="EmailPromotion=1"
ID="LinqDataSource1"
runat="server">
</asp:LinqDataSource>
|
For more information, see LinqDataSource Web Server Control Overview.