- 3,715,507 Users
- 2,242,778 Discussions
- 7,845,371 Comments
Forum Stats
Discussions
Categories
- 15 Data
- 362.2K Big Data Appliance
- 6 Data Science
- 1.5K Databases
- 461 General Database Discussions
- 3.7K Java and JavaScript in the Database
- 22 Multilingual Engine
- 487 MySQL Community Space
- 3 NoSQL Database
- 7.6K Oracle Database Express Edition (XE)
- 2.8K ORDS, SODA & JSON in the Database
- 416 SQLcl
- 42 SQL Developer Data Modeler
- 184.8K SQL & PL/SQL
- 21K SQL Developer
- 1.8K Development
- 3 Developer Projects
- 32 Programming Languages
- 135.1K Development Tools
- 8 DevOps
- 3K QA/Testing
- 246 Java
- 5 Java Learning Subscription
- 10 Database Connectivity
- 66 Java Community Process
- 1 Java 25
- 9 Java APIs
- 141.1K Java Development Tools
- 6 Java EE (Java Enterprise Edition)
- 153K Java Essentials
- 135 Java 8 Questions
- 86.2K Java Programming
- 270 Java Lambda MOOC
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 10 Java SE
- 13.8K Java Security
- 3 Java User Groups
- 22 JavaScript - Nashorn
- 18 Programs
- 124 LiveLabs
- 30 Workshops
- 9 Software
- 3 Berkeley DB Family
- 3.5K JHeadstart
- 5.7K Other Languages
- 2.3K Chinese
- 3 Deutsche Oracle Community
- 10 Español
- 1.9K Japanese
- 2 Portuguese
Ef6 code first with MapToStoredProcedures insert

I want to use a stored procedure with an insert on a table with a sequence. I have been unable to get the correct combination of parameters and C# code. This question on StackOverflow has a great code example of what I'm attempting to do. Unfortunately, it's been there for three years without an answer. I'm hioping for better results here.
Question 46201628 - entity-framework-is-not-able-to-map-out-param-from-oracle-stored-procedure
I can't link so I will borrow/quote the code from that post.
I start with a stored procedure. The output param (Number type) should return the just inserted Primary Key/sequence value to the C# code.
CREATE OR REPLACE PROCEDURE INSERT_EMPLOYEE ( p_employee_name IN EMPLOYEE.EMPLOYEE_NAME%TYPE ,OUT_EMPLOYEE_ID OUT EMPLOYEE.EMPLOYEE_ID%TYPE ) AS BEGIN INSERT INTO EMPLOYEE ( employee_name ) VALUES ( p_employee_name ) RETURNING employee_id into OUT_EMPLOYEE_ID; COMMIT; END INSERT_EMPLOYEE;
Here is my C# code (i.e. with the help of MapToStoredProcedures) making a call to INSERT_EMPLOYEE stored proc using EF6 and attempt to get the value in the OUT param (OUT_EMPLOYEE_ID in this case).
this.ToTable("EMPLOYEE"); .HasKey(model => model.EmployeeId); // Property Mappings this.Property(model => model.EmployeeId) .HasColumnName("EMPLOYEE_ID") .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity); this.Property(model => model.EmployeeName) .HasColumnName("EMPLOYEE_NAME"); // Configure Stored Procedures this.MapToStoredProcedures(p => { p.Insert(sp => sp.HasName("INSERT_EMPLOYEE") .Parameter(b => b.EmployeeName, "p_employee_name") .Result(re => re.EmployeeId, "OUT_EMPLOYEE_ID") ); });
When the application runs, it throws this exception. I can see that the output parameter has not been sent to the application.
OracleException: ORA-06550: line 1, column 8: PLS-00306: wrong number or types of arguments in call to 'INSERT_EMPLOYEE' ORA-06550: line 1, column 8: PL/SQL: Statement ignored
I have tried the same thing using a SYS_REFCURSOR (partial snippet only) without success.
RETURNING employee_id into v_EMPLOYEE_ID; OPEN OUT_ResultSet FOR SELECT v_EMPLOYEE_ID AS "OUT_EMPLOYEE_ID" FROM dual;
Answers
-
Here's a tutorial showing how to return an output parameter and a REF Cursor in EF6.
-
Alex, that doesn't answer my question. I know how to do output parameters and REF cursors. This is a situation using the MapToStoredProcedures functionality with code-first EF6. Any information needs to be specific to that usage.
-
Sorry, I was thinking about the traditional EF stored procedures rather than the newer Code First ones.