Pra*_*eep 5 sql-server stored-procedures entity-framework c#-4.0
我正在使用实体框架。我创建了一个名为 Customer 的实体对象并添加了我的存储过程。
我的存储过程包含另外两个存储过程,它们在输出参数中返回一些字符串。我将两个存储过程的输出参数值连接到主存储过程中。
主存储过程也在输出参数中返回结果字符串。
我还为主存储过程创建了一个函数导入以返回连接的字符串。
当我运行应用程序时,我收到“商店数据提供程序返回的数据读取器没有足够的列来满足所请求的查询”。
我在第一个和第二个过程中没有 select 语句。让我知道如何返回主存储过程的输出参数值。
在下面查找更多信息。
Create Procedure MainProcedure
@Id int,
@MainResult nvarchar(max) output
AS
Begin
declare @firstResult nvarchar(max)
declare @secondResult nVarchar(max)
declare @MainResult nVarchar(max)
Exec FirstSP @Id,@firstResult Output
Exec SecondSP @Id,@secondResult Output
Set @MainResult=@firstResult+@secondResult
End
Run Code Online (Sandbox Code Playgroud)
实体代码看起来像
System.Data.Objects.ObjectResult<string> resultList = null;
var OutputParamter =new ObjectParameter("MainResult",typeof(string));
resultList = ent.MainProcedure(ID, OutputParamter);
Run Code Online (Sandbox Code Playgroud)
我看不到你的存储过程来帮助你更多,但是当我使用存储过程并尝试通过“return”语句获取返回值时,我遇到了这个错误
IF EXISTS (SELECT * FROM Table)
return 0
Run Code Online (Sandbox Code Playgroud)
这在 sql server 上工作正常,但在 EF 上却不行。
我的解决方案是将 return 语句替换为 select 语句,如下所示:
IF EXISTS (SELECT * FROM Table)
--return 0
select @OUTPUT=0
Run Code Online (Sandbox Code Playgroud)
此链接了解更多信息。