Data Access has been discontinued. Please refer to this page for more information.

Selecting Data

This topic describes how to use an OpenAccessLinqDataSource control to select a subset of data from the table.

Selecting Which Columns to Retrieve

The Select property of OpenAccessLinqDataSource allows you to specify which columns will be retrieved from the target table. The following example shows the markup for part of an ASP.NET Web page that contains an OpenAccessLinqDataSource. The control is configured to enable the user to display the CategoryId and CategoryName columns from a table named Categories.

When you configure the control to select a subset of table columns, you will get a projection, which cannot be change-tracked, and therefore cannot be updated. The automatic inserts, updates, and deletes are not allowed as well.

    runat="server" EntityTypeName="" 
    Select="new (CategoryID, CategoryName)">

By default, when the Select property is not set and OpenAccessLinqDataSource retrieves the data for all the properties of the class.

Using the Selecting/Selected Events

The Selecting event occurs before a data-retrieval operation. You could handle the Selecting event in the following cases:

  • Generate the query programmatically.
  • Modify parameters and values for sorting, paging.
  • Cancel the data-retrieval operation.

The OpenAccessLinqDataSourceSelectEventArgs object that is passed to the event handler contains the parameters for the data-retrieval operation. You can modify the parameters in the Selecting event handler before the query executes.

protected void OpenAccessLinqDataSourceCategory_Selecting(object sender,
    Telerik.OpenAccess.Web.OpenAccessLinqDataSourceSelectEventArgs e)
   if (e.WhereParameters.ContainsKey("CategoryName"))
       e.WhereParameters["CategoryName"] = "Saloon";
Protected Sub OpenAccessLinqDataSourceCategory_Selecting(ByVal sender As Object, _
    ByVal e As Telerik.OpenAccess.Web.OpenAccessLinqDataSourceSelectEventArgs) _
    Handles OpenAccessLinqDataSource1.Selecting
 If e.WhereParameters.ContainsKey("CategoryName") Then
  e.WhereParameters("CategoryName") = "Saloon"
 End If
End Sub

The Selected event occurs when a data retrieval operation has finished. You could handle the selected event to catch any exceptions from the data retrieval operation.