Entity Framework is not able to map OUT param from Oracle Stored Procedure

Viewed 214

I am creating Stored Procedure for Insert in my Oracle DB with one input param and one output param.

Here is my stored proc(made it simple as of now.)

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 ADVENTUREWORKS.EMPLOYEE(
employee_name
)VALUES(
p_employee_name
) RETURNING employee_id into OUT_EMPLOYEE_ID;
COMMIT;
END INSERT_EMPLOYEE;

This output param(Number type) should return the just inserted Primary Key to the C# code.

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).

ToTable("ADVENTUREWORKS.EMPLOYEE");

        HasKey(model => model.EmployeeId);

        // Property Mappings
        Property(model => model.EmployeeId).HasColumnName("EMPLOYEE_ID").HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
        Property(model => model.EmployeeName).HasColumnName("EMPLOYEE_NAME");

        // Configure Stored Procedures
        this.MapToStoredProcedures(p =>
        {
            p.Insert(sp =>
                    sp.HasName("ADVENTUREWORKS.INSERT_EMPLOYEE").Parameter(b => b.EmployeeName, "p_employee_name")
                   .Result(re => re.EmployeeId, "OUT_EMPLOYEE_ID")
            );
        });

Here is my Employee Entity class with the EmpoyeeId as the Primary key of type Int64(long).

  public class Employee
        {
            public long EmployeeId { get; set; }

            public string EmployeeName { get; set; }
        }

but I am getting the type mismatch issue like below:

"innerException": {
      "message": "An error has occurred.",
      "exceptionMessage": "ORA-06550: line 1, column 8:\nPLS-00306: wrong number or types of arguments in call to 'INSERT_EMPLOYEE'\nORA-06550: line 1, column 8:\nPL/SQL: Statement ignored"
}

The Same thing is working fine if the primary key field is of type string and OUT param in Stored Proc is of type nvarchar2.

Any solutions will be highly appreciated.

0 Answers
Related