T
Telen
Guest
Telen Asks: Oracle EF Core - Execute Stored Procedure
i'm in the process of migrating from asp.net WinForms to dotnetcore - which is entertaining in itself, I've got everything I need to start migrating some of our more basic apps, apart from how the world I execute Stored Procedures from Oracle.
All the examples that I've seen reference SqlServer, but the context (swapped to Oracle equivalents just doesn't seem to work). I'm missing something but not sure what.
EF Core performs CRUD operations and FromSqlRaw with no issue, but I cannot for whatever reason figure out what I'm missing to get the Stored Procedure to work.
The procedure runs when in Oracle.
The function takes the ID and returns the relevant code, nothing complicated.
Model
DTO
Interface Call
Repository
The error message that I get when ran is
i'm in the process of migrating from asp.net WinForms to dotnetcore - which is entertaining in itself, I've got everything I need to start migrating some of our more basic apps, apart from how the world I execute Stored Procedures from Oracle.
All the examples that I've seen reference SqlServer, but the context (swapped to Oracle equivalents just doesn't seem to work). I'm missing something but not sure what.
EF Core performs CRUD operations and FromSqlRaw with no issue, but I cannot for whatever reason figure out what I'm missing to get the Stored Procedure to work.
The procedure runs when in Oracle.
The function takes the ID and returns the relevant code, nothing complicated.
Model
Code:
[Keyless]
public partial class PRODUCT_CODE
{
[StringLength(20)]
public string? PRODUCT { get; set; }
}
DTO
Code:
public class ProductCodeDto
{
[StringLength(20)]
public string? PRODUCT { get; set; }
}
Interface Call
Code:
public Task<IEnumerable<ProductListDto>> GetProductCode(int Id);
Repository
Code:
public async Task<IEnumerable<ProductListDto>> GetProductCode(int Id)
{
OracleParameter paramId = new OracleParameter("vId", Id);
OracleParameter paramReturn = new OracleParameter("return", OracleDbType.Varchar2, 20, ParameterDirection.Output);
string sql = ("BEGIN SCHEMA.GET_PRODUCT_CODE(:vId); END;");
var product = _db.PRODUCT_LISTS.FromSqlRaw(sql, paramId).ToList();
return _mapper.Map<IEnumerable<PRODUCT_LIST>, IEnumerable<ProductListDto>>(product);
}
The error message that I get when ran is
Code:
PLS-00221: 'GET_PRODUCT_CODE' is not a procedure or is undefined
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
at OracleInternal.ServiceObjects.OracleConnectionImpl.VerifyExecution(Int32& cursorId, Boolean bThrowArrayBindRelatedErrors, SqlStatementType sqlStatementType, Int32 arrayBindCount, OracleException& exceptionForArrayBindDML, Boolean& hasMoreRowsInDB, Boolean bFirstIterationDone)
at OracleInternal.ServiceObjects.OracleCommandImpl.ExecuteReader(String commandText, OracleParameterCollection paramColl, CommandType commandType, OracleConnectionImpl connectionImpl, OracleDataReaderImpl& rdrImpl, Int32 longFetchSize, Int64 clientInitialLOBFS, OracleDependencyImpl orclDependencyImpl, Int64[] scnForExecution, Int64[]& scnFromExecution, OracleParameterCollection& bindByPositionParamColl, Boolean& bBindParamPresent, Int64& internalInitialLOBFS, Int64 internalInitialJSONFS, OracleException& exceptionForArrayBindDML, OracleConnection connection, IEnumerable`1 adrianParsedStmt, Boolean isDescribeOnly, Boolean isFromEF)
at Oracle.ManagedDataAccess.Client.OracleCommand.ExecuteReader(Boolean requery, Boolean fillRequest, CommandBehavior behavior)
at Oracle.ManagedDataAccess.Client.OracleCommand.ExecuteDbDataReader(CommandBehavior behavior)
at Oracle.EntityFrameworkCore.Storage.Internal.OracleRelationalCommandBuilderFactory.OracleRelationalCommandBuilder.OracleRelationalCommand.ExecuteReader(RelationalCommandParameterObject parameterObject)
at Microsoft.EntityFrameworkCore.Query.Internal.FromSqlQueryingEnumerable`1.Enumerator.InitializeReader(Enumerator enumerator)
at Oracle.EntityFrameworkCore.Storage.Internal.OracleExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
at Microsoft.EntityFrameworkCore.Query.Internal.FromSqlQueryingEnumerable`1.Enumerator.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at OracleTestApp_Repository.Repository.ProductListRepository.GetProductCode(Int32 Id) in C:\Users\VEL017\Documents\Core5\OracleTestApp\OracleTestApp_Repository\Repository\ProductListRepository.cs:line 94
at OracleTestApp_Server.Pages.ProductList.ProductIndividual.SearchButton() in C:\Users\VEL017\Documents\Core5\OracleTestApp\OracleTestApp\Pages\ProductList\ProductIndividual.razor:line 128
at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)