Telerik OpenAccess Classic

Telerik OpenAccess ORM Send comments on this topic.
How to: Use the Forward Mapping Wizard
Programmer's Guide > OpenAccess ORM Classic (Old API) > OpenAccess Tasks > Defining a Data Model > How to: Use the Forward Mapping Wizard

Glossary Item Box

This documentation article is a legacy resource describing the functionality of the deprecated OpenAccess Classic only. The contemporary documentation of Telerik OpenAccess ORM is available here.

The Forward-Mapping wizard is a very helpful design-time tool provided by OpenAccess. It is used for defining and editing various mapping settings in a user-friendly graphic interface.

For the purpose of the task we define a common class-model where we have two classes in a 1:n relation: "Order" and "OrderDetails".

C# Copy Code
   public class Order
   {
       
private string customer;       
       
private DateTime orderDate;
       
private string shipAddress;
       
private IList<OrderDetail> details = new List<OrderDetail>();
       ...      
   }
   
public class OrderDetail
   {
       
private string product;
       
private float price;
       
private int quantity;
       
private Order order;
       ...        
   }

 

VB .NET Copy Code
Public Class Order
 Private customer As String
 Private orderDate As DateTime
 Private shipAddress As String
 Private details As IList(Of OrderDetail) = New List(Of OrderDetail)()
...
End Class
Public Class OrderDetail
 Private product As String
 Private price As Single
 Private quantity As Integer
 Private order As Order
...
End Class

After we have enabled our project to use OpenAccess we can start the forward-mapping wizard from the VisualStudio main menu.

 

Making a class persistent

The first screen that the wizard shows is a table with all the classes in our project and checkboxes in a "Make Persistent" column for every class. When checked, OpenAccess generates the [Telerik.OpenAccess.Persistent()] attribute for a class that the user wants to persist into the database.

 

C# Copy Code
  [Telerik.OpenAccess.Persistent()]
   
public class Order
   {
    ...
   }
VB .NET Copy Code
<Telerik.OpenAccess.Persistent> _
Public Class Order
...
End Class

After we have defined our desired classes a persistent, child-nodes under the "Persistent" node of the TreeView on the left of the wizard are created for them.

 

Class-specific options in the Forward Mapping Wizard

There are tree sections in the forward mapping wizard for every class: Class Mapping, FetchGroup, Index

 

The Class Mapping section

The Class Mapping section exposes the most important settings which will be used when OpenAccess creates the database schema base on our class model.

There are few groups of settings in the Class Mapping section:

  • In the DB Table Name we can manually type the name of the table that OpenAccess will create for the selected class in the database.
  • In the "Identity" group, the user defines how the records in the database table will be identified. There under the "Type" combo-box there are three options for the identity type:
    1. "Internal" means that OpenAccess is going to create separate column which will be used as the identity for a record in the table for the selected class
    2. "Single Field" means that one of our defined fields in the class will be used for identity. If we choose "Single Field" additional combo-box appears underneath where the user chooses which field should be used as identity.
    3. "Multiple Fields" means that our class will be identified by multiple columns in the table that maps in the database.

 The last combo-box in the identity group is called "Key Generator". There are few options that can be set:       AUTOINC, HIGHFLOW, NONE, VERIFY.

The AUTOINC and HIGHFLOW key generators can be used only if the id field is of type integer(or related to integer) or the user has chosen "Internal" from the "Type" combo box

 

  • Next comes the "Concurrency Control" group where the default value is set to version. That is the most recommended way for concurrency control as OpenAccess automatically creates a column for that purpose which it uses internally. If these column is not desired by the developer or the database is an existing one and can not afford changes in schema there are tree other options to handle the concurrency control: "timestamp"(which is defined at the client side), "changed" and "none" which is not recommended for multiple access applications.
  • Under the "Concurrency Control" group there is a check-box "Create/Update Table" that points whether a table should be created or updated for the class with the specified settings from the wizard
  • The last group of settings is the "Inheritance" group where settings for a class involved in a class hierarchy are defined. Refer to the related topic where handling inheritance with OpenAccess is discussed

The Fetch Group section

Fetch Groups are one of the features serving for query optimization delivered by OpenAccess. We can manage groups for each class in the Fetch Group section. Fetch groups and managing them using the Forward Mapping Wizard are described in more details in the related topic.

 

Field-specific options in the Forward Mapping Wizard

In the treeview for navigation on the left-side pannel of the Forward Mapping Wizard there are child-nodes to all classes which expose every field of the class. When one of those property nodes is clicked settings for the related field are given in the main pannel of the wizard.

The settings given in the main pannel could be deferent depending on the type of the selected field.

  • If the field is a simple one and not referencing any other classes the main pannel has looks similar to the following:

There we can define settings for the database column, skip the field from generating into a column or mark the field to be serialized into Blob if the type of the field is more specific(Cookie, IpAddress etc.)

  • If we select a field that is a reference to another persistent class like the "order" filed in the OrderDetails class the settings exposed are shown here:

Here besides the settings previously mentioned we can also define constrain-related settings as well as the type of join that will be used into the generated SQL query when accessing this object.

  • The last field-specific view of the forward mapping wizard is when a collection field is selected. For an example we have the "details" collection of the Order class which contains all the OrderDetail objects referring to a specific "Order" instance in the object graph.

There are several additional options in this dialog. The type of the relation is specified, whether a join table should be used for that relation and settings for the join table if chosen as well. Another useful feature is the "cascading delete" check box which would cause all the related OrderDetail objects to be deleted alongside their parent Order object. When checked the "Cascading Delete" check-box OpenAccess generates the Telerik.OpenAccess.Depend attribute to the field it was specified for. This attribute tells OpenAccess it should use cascading delete.

C# Copy Code
  [Telerik.OpenAccess.Persistent()]
   
public class Order
   {
    ...
      [Telerik.OpenAccess.Depend()]
       
private IList<OrderDetail> details = new List<OrderDetail>();
   }

 

VB .NET Copy Code
<Telerik.OpenAccess.Persistent> _
Public Class Order
...
 <Telerik.OpenAccess.Depend> _
 Private details As IList(Of OrderDetail) = New List(Of OrderDetail)()
End Class