Stored Procedures
- 3 minutes to read
Support for stored procedures in XPO includes the following capabilities.
#Direct Calling of Existing Stored Procedures
You can use the following methods to call stored procedures:
To simplify implementation, the Data Model Wizard can optionally generate all the required persistent classes and DDL (Data Description Language) code for views, triggers, and stored procedures.
When the Import stored procedures option is enabled, the following wizard page is activated.
The wizard generates the static SprocHelper class located in the StoredSprocHelper.cs (StoredSprocHelper.vb) file. This class exposes the following static methods that wrap the Session.ExecuteSproc and Session.GetObjectsFromSproc methods:
Method Name | Description |
---|---|
Exec<Stored |
Calls the <Stored |
Exec<Stored |
Calls the <Stored |
Exec<Stored |
Calls the <Stored |
The <StoredProcedureName>Result is a non-persistent class generated by the wizard which represents the stored procedure result. Properties of this class correspond to result set columns selected in the wizard pare illustrated above.
The code sample below demonstrates how to use the generated static method to call a stored procedure:
public IList<CountEmployeesByClassificationResult> GetEmployeesByClassification(Session session) {
// The ExecHR_CountEmployeesByClassificationIntoObjects method was generated by Data Model Wizard.
return SprocHelper.ExecHR_CountEmployeesByClassificationIntoObjects(session).ToList();
}
#Mapping of Persistent Classes to Microsoft SQL Server and Oracle Database Views
This mapping is performed with the help of INSTEAD-OF triggers and stored procedures, requires the following tasks to be performed:
- Create a database view.
- Map a persistent class to this view.
- Create stored procedures for INSERT, UPDATE and DELETE functionalities.
- Create INSTEAD-OF triggers, routing this functionality to the created stored procedures.
Note
The Advantage, DB2, Firebird, My
Note
You can try the functionality described here in the Querying a Data Store | Stored Procedures section of the XPO Tutorials demo (C:\Users\Public\Documents\DevExpress Demos 24.