我通过 LINQ 以一种相当简单的方式调用存储过程:
[Function(Name = "dbo.add_second_override")]
public int AddSecondOverride(
[Parameter(DbType = "numeric(10)")] decimal account_id,
[Parameter(DbType = "numeric(10)")] decimal security_id,
[Parameter(DbType = "varchar(255)")] string reason,
[Parameter(DbType = "numeric(10)")] decimal? order_id,
[Parameter(DbType = "numeric(10)")] decimal current_user)
{
IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), new object[] { account_id, security_id, reason, order_id, current_user });
if ((int)result.ReturnValue != 0)
{
string errorDescription = Sysmessages.FirstOrDefault(x => x.Error == (int)result.ReturnValue).Description;
throw new Exception(errorDescription);
}
return (int)result.ReturnValue;
}
这工作正常,但如果存储过程中有一个 SQL 打印语句,我如何提取这些信息?例如
create procedure dbo.add_second_override
(
@account_id numeric(10),
@security_id numeric(10),
@reason varchar(255) = null output,
@order_id numeric(10) = null,
@current_user numeric(10)
)
as
begin
/* Do some other stuff */
print 'This is a SQL message'
return 0
end
曾经有一种方法可以使用 SQLClient 检索此消息,但我找不到与 LINQ 相关的任何内容。
请注意,我无法在存储过程中引发异常,而不是使用“打印”。它必须以某种方式获取打印语句。