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

Selecting Data

This article is relevant to entity models that utilize the deprecated Visual Studio integration of Telerik Data Access. The current documentation of the Data Access framework is available here.

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 tab on the second page of the wizard (the Configure Data Selection dialog) allows you to specify which columns will be retrieved from the target table.

(*) is the default selection. This option means that all properties/columns from the target table will be selected. When you check the Select All (*) option, full entities are returned instead of results that contain individual properties.

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 all columns from a table named Categories.

<telerik:OpenAccessLinqDataSource
   ID="OpenAccessLinqDataSource"
   runat="server"
   ContextTypeName="OpenAccessLinqDataSourceDemo.EntitiesModel"
   ResourceSetName="Categories"
   EntityTypeName="">
</telerik:OpenAccessLinqDataSource>

If you choose specific properties, you won't get an entity object back. Instead, you will get a projection, which cannot be change-tracked, and therefore cannot be updated. In this case automatic inserts, updates, and deletes are not allowed.

You cannot insert, update or delete records when you are selecting specific properties, i.e. you are not using the default (*) selection.

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.

<telerik:OpenAccessLinqDataSource
   ID="OpenAccessLinqDataSource"
   runat="server"
   ContextTypeName="OpenAccessLinqDataSourceDemo.EntitiesModel"
   ResourceSetName="Categories"
   EntityTypeName=""
   Select="new (CategoryID, CategoryName)">
</telerik:OpenAccessLinqDataSource>

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 OpenAccessLinqDataSource_Selecting(object sender,
    Telerik.OpenAccess.Web.OpenAccessLinqDataSourceSelectEventArgs e)
{
   if (e.WhereParameters.ContainsKey("CategoryName"))
   {
       e.WhereParameters["CategoryName"] = "Saloon";
   }
}
Protected Sub OpenAccessLinqDataSource_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.

For a complete UI reference of the Select tab page, check out the Select Settings topic.