[英]Call Oracle stored procedures using devart dotConnect
I'm new in Entity Framework and trying to call oracle stored procedures, but without success. 我是Entity Framework的新成员,并尝试调用oracle存储过程,但未成功。 So Here is my question:
所以这是我的问题:
How to call oracle stored procedures using devart dotConnect? 如何使用devart dotConnect调用oracle存储过程?
For example, I have stored procedure: 例如,我有存储过程:
procedure get_problems(res out sys_refcursor) is
begin
open res
for
select id, name
from problems;
end;
And from C# I'm tying to call: 从C#我想打电话给:
using (Entities entities = new Entities())
{
ObjectParameter res = new ObjectParameter("res", typeof(byte[]));
ObjectResult<PROBLEM> problems = entities.SelectAllProblems(res);
}
But it throws "EntityCommandExecutionException": 但是会抛出“ EntityCommandExecutionException”:
An error occurred while executing the command definition.
执行命令定义时发生错误。 See the inner exception for details.
有关详细信息,请参见内部异常。
Here is the inner exception: 这是内部的例外:
ORA-06550: line 2, column 3:\\nPLS-00306: wrong number or types of arguments in call to 'GET_PROBLEMS'\\nORA-06550: line 2, column 3:\\nPL/SQL: Statement ignored
ORA-06550:第2行,第3列:\\ nPLS-00306:调用“ GET_PROBLEMS”时参数的数量或类型错误\\ nORA-06550:第2行,第3列:\\ nPL / SQL:语句被忽略
I used 我用了
"typeof(byte[])"
“ typeof(byte [])”
as ObjectParameter type, because I saw this in Devart Entity Developer's generated code. 作为ObjectParameter类型,因为我在Devart Entity Developer的生成代码中看到了这一点。
ps By the way, how will you recommend dotConnect in large projects? ps顺便说一下,您如何在大型项目中推荐dotConnect?
I know this was asked a while ago but it might help someone else as it took me a while to figure this out. 我知道这个问题是在不久前被问到的,但它可能会帮助其他人,因为我花了一些时间才弄清楚这一点。 Here's how we call a stored proc (SID_PGet) within a package (P_SID) and return a single string value using DotConnect.
这是我们在包(P_SID)中调用存储的proc(SID_PGet)并使用DotConnect返回单个字符串值的方式。 (This only returns a single value - I'm currently trying to find out how to return a sys_refcursor).
(这仅返回一个值-我目前正在尝试找出如何返回sys_refcursor)。
Here's the stored proc: 这是存储的过程:
PROCEDURE SID_PGet(io_SID OUT varchar2) is
Begin
io_SID:=GetSID; -- GetSID returns a unique varchar value
End;
And in the DbContext in C#: 在C#的DbContext中:
public string GetNextSId()
{
var parameter = new Devart.Data.Oracle.OracleParameter("io_SID", Devart.Data.Oracle.OracleDbType.VarChar, ParameterDirection.Output);
this.Database.ExecuteSqlCommand("BEGIN P_SID.SID_PGet(:io_SID); END;", parameter);
var sid = parameter.Value as string;
return sid;
}
Take a look at this article in our blog. 看看我们博客中的这篇文章 。
You can contact us using our Forums or Feedback Page . 您可以使用我们的论坛或反馈页面与我们联系。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.