- 3,708,745 Users
- 2,241,117 Discussions
- 7,840,574 Comments
Forum Stats
Discussions
Categories
- 9 Data
- 362.2K Big Data Appliance
- 3 Data Science
- 1K Databases
- 322 General Database Discussions
- 3.7K Java and JavaScript in the Database
- 22 Multilingual Engine
- 479 MySQL Community Space
- 3 NoSQL Database
- 7.6K Oracle Database Express Edition (XE)
- 2.7K ORDS, SODA & JSON in the Database
- 408 SQLcl
- 32 SQL Developer Data Modeler
- 184.6K SQL & PL/SQL
- 20.9K SQL Developer
- 1.3K Development
- Developer Projects
- 31 Programming Languages
- 134.5K Development Tools
- 4 DevOps
- 3K QA/Testing
- 173 Java
- 3 Java Learning Subscription
- 6 Database Connectivity
- 64 Java Community Process
- Java 25
- 7 Java APIs
- 141.1K Java Development Tools
- 2 Java EE (Java Enterprise Edition)
- 153K Java Essentials
- 132 Java 8 Questions
- 86.1K Java Programming
- 270 Java Lambda MOOC
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 5 Java SE
- 13.8K Java Security
- 3 Java User Groups
- 22 JavaScript - Nashorn
- 18 Programs
- 80 LiveLabs
- 23 Workshops
- 7 Software
- 3 Berkeley DB Family
- 3.5K JHeadstart
- 5.7K Other Languages
- 2.3K Chinese
- 3 Deutsche Oracle Community
- 6 Español
- 1.9K Japanese
- 2 Portuguese
How to get a string from a stored procedure with Oracle EntityFramework Core?
This stored procedure is just to demonstrate a problem.
create or replace PROCEDURE SP_TEST_CSHARP (word IN varchar2,upperword OUT varchar2) AS
begin
select upper(word) into upperword from dual;
end;
I created this model,
{
public string upperword{ get; set; }
}
I tried this:
OracleParameter upperword = new OracleParameter("upperword",OracleDbType.Varchar2, ParameterDirection.Output);
var result = _dbContext.rsProcedures.FromSqlRaw("begin SP_TEST_CSHARP(:word, :upperword); end;", word, upperword);
So i get this error message:
System.InvalidOperationException: The required column 'upperword' was not present in the results of a 'FromSql' operation.
Could anyone tell me what I'm doing wrong?
Thank you very much
Answers
I don't believe EF Core itself supports stored procedures that return non-entity data yet. See this GitHub Issue that tracks EF Core stored procedure mapping support. The "General data retrieval using stored procedures" is being tracked, but not completed yet by Microsoft.
I tried your test case and a few variations of it myself with no luck. You will have to use the stored procedure outside of EF Core, then return the data to your EF Core app.
With EF Core 2 and 3.1 I was able to do what you're asking in another way (without using a model).
var inParamString1 = new OracleParameter("InParamString1", OracleDbType.Int64, ParameterDirection.Input);
var inParamString2 = new OracleParameter("InParamString2", OracleDbType.Varchar2, ParameterDirection.Input);
var outParamResult =
new OracleParameter("OutParamResult", OracleDbType.Varchar2, 50, output, ParameterDirection.Output);
inParamString1.Value = 1;
inParamString2.Value = "asdasd";
var result = await dbContext.Database.ExecuteSqlCommandAsync(
"BEGIN PROCEDURENAME (:InParamString1, :InParamString2, :OutParamResult); END;",
inParamString1, inParamString2, outParamResult);
var hereYourStringFromTheProcedure= outParamResult.Value.ToString();
If you updated Oracle.EntityFrameworkCore to the latest 3.19.80 it would be better to use the new method
await dbContext.Database.ExecuteSqlRawAsync(
"BEGIN PROCEDURENAME (:InParamString1, :InParamString2, :OutParamResult); END;",
inParamString1, inParamString2, outParamResult);
I think it would be doable also by defining the model as you did but I didn't have enough time to make it work.