This topic is applicable to Entity Framework v1 - v6. It is not applicable to Entity Framework Core because Entity Developer generates ADO.NET code for invoking stored procedures in this case.
In this chapter we consider an usage of stored procedures with ORM tools.
CREATE PROCEDURE GET_DEPT_PROC(curParam OUT SYS_REFCURSOR) IS BEGIN OPEN curParam FOR SELECT * FROM DEPT ORDER BY DEPTNO; END;
Expand the connection node in the Database Explorer, then your schema node and then the Stored Procedures node. Drag the GET_DEPT_PROC to the diagram sheet. The function will be created in the storage model, its REF CURSOR parameter is hidden and its ResultSetParameterName attribute is automatically set to the needed parameter. Corresponding method will be automatically created in the conceptual model. However, you need to set the return type for it manually. To do this perform the following actions:
You also may drag the procedure from Database Explorer to the storage model node in the Model Explorer. In such case only the storage model is updated, the corresponding method is not created. To create corresponding method, drag the procedure from the Model Explorer to the diagram sheet or right-click it in the Model Explorer and select Create Method from the popup menu.
<Function Name="GET_DEPT_PROC" Aggregate="false" BuiltIn="false" NiladicFunction="false" IsComposable="false" ParameterTypeSemantics="AllowImplicitConversion" Schema="SCOTT"> <Parameter Name="CURPARAM" Type="REF CURSOR" Mode="Out" /> </Function>We need to perform some XML code changes manually to use this procedure in our model.
xmlns:devart="http://devart.com/schemas/edml/StorageSchemaExtensions/1.0"
<Function Name="GET_DEPT_PROC" Aggregate="false" BuiltIn="false" NiladicFunction="false" IsComposable="false" ParameterTypeSemantics="AllowImplicitConversion" Schema="SCOTT" devart:ResultSetParameterName="CURPARAM"> </Function>
This example illustrates call of the method, retrieving the collection of entities, and entity output to console. Object context name and case of the Depts class and its fields may differ in your case.
Entity Framework Tutorial | Using Entity Data Model Wizard | Stored Routines in Entity Framework Model | Creating Database and Model | Stored Function Returning REF CURSOR | Mapping CUD Operations to Stored Routines