使用EF获取存储过程中的返回值

时间:2014-07-14 07:57:02

标签: c# entity-framework stored-procedures

我在我的MVC项目中使用EF(在.Net 4.5中)并使用存储过程来获取数据。我的问题是,当EF要求我返回一组对象时,我不知道如何获得返回值。这是一个例子:

  Param:
  @id                AS NVARCHAR(5), 
  @out_error_code    AS INT output, 
  @out_error_message AS NVARCHAR(200) output 
  AS 
  BEGIN 
  DECLARE @int_return AS INT 

  BEGIN try 
      SET @int_return = 1 

      SELECT * 
      FROM   dbo.something
      WHERE  id = @id 

      SET @int_return = 0 
  END try 

  BEGIN catch 
      SET @out_error_code = Error_number() 
      SET @out_error_message = Error_message() 

      RETURN @int_return 
  END catch 
  END 

此代码是自动生成的:

  public virtual ObjectResult<DetailEmployee_Result> DetailEmployee(string id, ObjectParameter out_error_code, ObjectParameter out_error_message){
        var idParameter = id != null ?
            new ObjectParameter("id", id) :
            new ObjectParameter("id", typeof(string));

        return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<DetailNhanvien_Result>("DetailNhanvien", idParameter, out_error_code, out_error_message);
    }

在这种情况下,我可以获得@return_value = 1(意味着错误)吗?

感谢。

0 个答案:

没有答案