【发布时间】:2011-09-21 06:09:11
【问题描述】:
我有一个存储过程,它根据输入返回多行整数或多行日期时间。
我查看了this question 的答案,并阅读并实施了Handling Multiple Result Shapes from SPROCs 的 Scott Guthries 解决方案(向下滚动页面查看该部分。)
不幸的是,它无法正常工作。
这是我的代码:
[Function(Name = "FunkyStoredProcedure")]
[ResultType(typeof(List<int>))]
[ResultType(typeof(List<DateTime>))]
public IMultipleResults FunkyStoredProcedure(int appId, int sId, int cId)
{
IExecuteResult result = this.ExecuteMethodCall(this, (MethodInfo)(MethodInfo.GetCurrentMethod()), appId, sId, cId);
return (IMultipleResults)result.ReturnValue;
}
}
使用 SQL Server Profiler,Linq 2 Sql 生成如下代码:
declare @p6 int
set @p6=0
exec sp_executesql N'EXEC @RETURN_VALUE = [FunkyStoredProcedure] @appId = @p0, @sId = @p1, @cId = @p2',N'@p0 int,@p1 int,@p2 int,@RETURN_VALUE int output',@p0=2,@p1=4,@p2=2,@RETURN_VALUE=@p6 output
select @p6
这会产生如下所示的结果集:
cId
-----------
694
42
43
41
4732
-----------
0
(1 row(s) affected)
注意这里有两个结果集(应该只有一个。)并注意第二个结果集,返回给LinqToSql的那个是0!
“exec sp_executesql...”行生成第一个正确的结果集。
“select @p6”行生成第二个不正确的结果集。
首先,为什么@p6 被定义为一个int?在函数中,我有两种可能的 ResultType:List 和 List 这似乎是一个问题。
第二,为什么不返回存储过程的输出?而是返回 @p6 的值?
最后,最重要的是,我怎样才能让它正常工作?
【问题讨论】:
标签: c# linq-to-sql stored-procedures