[英]How can I use IMultipleResults AND return Output Parameters from a SQL Stored procedure?
I have a SQL Stored Procedure that I am accessing using Linq-To-SQL.我有一个 SQL 存储过程,我正在使用 Linq-To-SQL 访问它。 It is returning multiple resultsets as well as a couple output parameters.
它返回多个结果集以及一对 output 参数。 It works when I run the procedure as a Query within SQL, but when I try to access it from my C# code, it does not want to work.
当我在 SQL 中将过程作为查询运行时,它可以工作,但是当我尝试从我的 C# 代码访问它时,它不想工作。 The 'UserHasAccessToOption' parameter always returns false, even though it is only set to true in the Stored Procedure.
'UserHasAccessToOption' 参数始终返回 false,即使它在存储过程中仅设置为 true。
Again, it returns and allows me to browse the other ResultSets that are returned by the Stored Procedure, but it does not return ANY SQL output parameters.同样,它返回并允许我浏览存储过程返回的其他结果集,但它不返回任何 SQL output 参数。
Here is my code to access the stored procedure and return the IMultipleResults object:这是我访问存储过程并返回 IMultipleResults object 的代码:
[FunctionAttribute(Name = "dbo.GetOption")]
[ResultType(typeof(Option))]
[ResultType(typeof(LoanPurpose))]
[ResultType(typeof(LoanType))]
[ResultType(typeof(User))]
[ResultType(typeof(Client))]
[ResultType(typeof(OrganizationFinancialItem))]
public IMultipleResults GetOption(
int? OptionID,
int UserID,
bool GetClients,
bool GetOtherOrganizationUsers,
bool GetLoanPurposes,
bool GetLoanTypes,
bool GetOrganizationFinancialItems,
ref bool? UserHasAccessToOption)
{
using (profiler.Step("Call \"GetOption\" SProc"))
{
IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod()))
, OptionID
, UserID
, GetClients
, GetOtherOrganizationUsers
, GetLoanPurposes
, GetLoanTypes
, GetOrganizationFinancialItems
, UserHasAccessToOption);
return (IMultipleResults)(result.ReturnValue);
}
}
The values of the output parameters are sent last in the data stream from the database, so you have to read to the end of the last result set before you can get the output parameters. output参数的值在数据库中的数据stream中最后发送,所以必须读取到最后一个结果集的末尾才能获取Z78E6221F6393D1356681DB398F14CED参数。
I recommend you see the "Handling Multiple Result Shapes from SPROCs" section of this valuable article:我建议您查看这篇有价值的文章的“处理来自 SPROC 的多个结果形状”部分:
LINQ to SQL (Part 6 - Retrieving Data Using Stored Procedures) LINQ 到 SQL(第 6 部分 - 使用存储过程检索数据)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.