Telerik OpenAccess Classic

Telerik OpenAccess ORM Send comments on this topic.
Reverse Mapping Stored Procedures
Programmer's Guide > OpenAccess ORM Classic (Old API) > Programming With OpenAccess > Stored Procedures Support > Reverse Mapping Stored Procedures

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.

Telerik OpenAccess ORM provides the ability to import and use stored procedures already existing in the database. They can be mapped to static methods or used internally to replace the default write operations and implement custom logic.

To specify a stored procedure to be used for insert, update or delete operation, open the Reverse mapping wizard and select the class which will use the procedures. Enable the “Use Stored Procedures” checkbox. The grid below displays the available operations which can be mapped to a stored procedure along with their necessary parameters. In the following example, the “DeleteCategory” stored procedure is set to be used for deleting Category objects. This procedure requires one parameter of type integer (Param1) which should be associated with the ID property of the Category class. If the signature of a stored procedure does not have the necessary parameters for particular operation, then this procedure will not be listed in the combobox next to the operation name.


To force Telerik OpenAccess ORM to generate automatically a stored procedure for an operation, choose the “<Create Stored Procedure>” option from the same combobox. The default name for this procedure which will be created is shown in the left column of the grid. If you do not want to use a stored procedure for some of the write operations, set the option “<Use Dynamic SQL>”. This will keep the default mechanism provided by Telerik OpenAccess ORM.
The other major ability of the Reverse mapping wizard is mapping existing stored procedures to standalone static methods that can be called from the application code when needed. To map a procedure, select the “Stored Procedures” node from the treeview.

The grid lists all stored procedures available on the server.

Use the “Merge schema changes with existing settings” button to refresh the grid if not all stored procedures are shown.

To generate a method, enable the checkbox next to the stored procedure name. The method name and the type of the returned result can be set as well. The default result type is object array which elements are also object arrays containing the values from the different columns returned by the stored procedure. The following code can be used to aggregate a list with all values from the second column of the result returned by the “SalesByYear” procedure.

C# Copy Code
IQueryResult result = StoredProcedure.SalesByYear(scope, new DateTime(1994, 12, 12), new DateTime(1999, 12, 12));
int> ids = new List<int>();
for (int i = 0; i < result.Count; i++)
object[] elem = (object[])result[i];
VB.NET Copy Code
Dim result As IQueryResult = StoredProcedure.SalesByYear(scope, New DateTime(1994, 12, 12), New DateTime(1999, 12, 12))
Dim ids As List(Of Integer) = New List(Of Integer)()
For i As Integer = 0 To result.Count - 1
 Dim elem() As Object = CType(result(i), Object())
Next i

If a procedure returns ID fields of a certain class, then the result can be returned as a generic IEnumerable of that class. In the example, the “TenMostExpensiveProducts” method is configured to return an IEnumerable of Products.

C# Copy Code
IEnumerable<Product> result = (IEnumerable<Product>)StoredProcedure.TenMostExpensiveProducts(scope);
VB.NET Copy Code
Dim result As IEnumerable(Of Product) = CType(StoredProcedure.TenMostExpensiveProducts(scope), IEnumerable(Of Product))

All methods generated from stored procedures take place in a file named “StoredProcedure.cs” and can be called via the static StoredProcedure class.

Custom stored procedures defined in the App.config file and already forward mapped, should show up in the Reverse mapping wizard and can be mapped to methods as well.