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

Inserting 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.

In this task, you will extend the code to enable you to create new Car objects.

  1. Open the Default.aspx page in Design view.
  2. Select the OpenAccessLinqDataSourceCar and expand the SmartTag panel.
  3. Set the Enable insert property to True. This will enable the OpenAccessLinqDataSource control to automatically handle insert operations. You could find more information, here.

Run your application and try to insert a new Car object. Note that when you try to create a new car record, you should enter a CategoryID. In the SofiaCarRental database, there is an one-to-many relation between the Cars and Categories tables. The CategoryID property should match an existing Category.

In other words, the Car entity has a reference to the Category entity. The next step is to modify the RadGrid control to use a GridDropDownColumn to display all categories:

  1. Open the Default.aspx page in Source view.
  2. Locate the definition for the CategoryID column in the RadGrid.MasterTableView.

    <telerik:GridBoundColumn DataField="CategoryID" DataType="System.Int32" 
       FilterControlAltText="Filter CategoryID column" HeaderText="CategoryID" 
       SortExpression="CategoryID" UniqueName="CategoryID">
  3. And replace with this. This is the moment when you are going to use the second OpenAccessLinqDataSource control.

    <telerik:GridDropDownColumn UniqueName="DropDownCategoryListColumn" ListTextField="CategoryName"
       ListValueField="CategoryID" DataSourceID="OpenAccessLinqDataSourceCategory" HeaderText="Category"
       DataField="CategoryID" DropDownControlType="RadComboBox" AllowSorting="true"
       ItemStyle-Width="120px" />

Run your application again, and try to add a new car record. This time, all categories will be shown in the drop-down.