EF6 - ExecuteSqlCommandAsync - Get return parameter (declare scalar variable error)(EF6 - ExecuteSqlCommandAsync - 获取返回参数(声明标量变量错误))
问题描述
我有以下代码:
object[] parameters =
{
new SqlParameter("@val1", val1),
new SqlParameter("@val2", val2),
new SqlParameter
{
ParameterName = "@retVal",
SqlDbType = SqlDbType.Int,
Direction = ParameterDirection.ReturnValue,
Value = -1
}
};
await context.Database.ExecuteSqlCommandAsync("EXEC @retVal = Example_SP @val1, @val2", parameters);
我使用的 SP 很好,可以在 SQL MS 中返回一个值.但是当我使用 EF 执行它时,我被告知必须声明标量变量 @retVal".这不是我的 SqlParameter 做的吗??
The SP I'm using is fine and returns a value in SQL MS fine. But when I execute it using EF I am told I 'must declare the scalar variable @retVal'. Isn't that what my SqlParameter does??
我已经尝试从参数中删除@"符号,正如一些人在其他地方所建议的那样,但据我了解,@"符号是可选的,无论如何都没有区别.
I've tried removing the '@' sign form the parameters, as some have suggested elsewhere, but as I understand it the '@' sign is optional and makes no difference anyway.
如何使用 ExecuteSqlCommandAsync 从 SP 获取返回值而不导致错误?
How do I get the return value from the SP without causing errors, using ExecuteSqlCommandAsync?
谢谢!
推荐答案
你需要使用 ParameterDirection.Output
而不是 ParameterDirection.ReturnValue
.
You need to use ParameterDirection.Output
instead of ParameterDirection.ReturnValue
.
这篇关于EF6 - ExecuteSqlCommandAsync - 获取返回参数(声明标量变量错误)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:EF6 - ExecuteSqlCommandAsync - 获取返回参数(声明标量变量错误)


基础教程推荐
- 全局 ASAX - 获取服务器名称 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01