ExecuteSqlCommand with output parameter

前端 未结 6 1021
名媛妹妹
名媛妹妹 2020-12-06 04:43

I\'m using Entity Framework in an ASP.NET MVC3 application and I\'m trying to use the following code:

var token = \"\";
this.Database.ExecuteSqlCommand(\"exe         


        
6条回答
  •  感动是毒
    2020-12-06 05:08

    Below is what I do for Oracle using the DevArt driver. I have a package.proc called P_SID.SID_PGet that returns a single string value. The proc is:

    PROCEDURE SID_PGet(io_SID OUT varchar2) is
    Begin
       io_SID:=GetSID; -- GetSID just goes off and gets the actual value
    End;
    

    Below is how I call it and retrieve the SID value (I'm using this with EF 4.1 code first and this method is in the DbContext):

    /// 
    /// Get the next SID value from the database
    /// 
    /// String in X12345 format
    public string GetNextSId()
    {
        var parameter = new Devart.Data.Oracle.OracleParameter("io_SID", Devart.Data.Oracle.OracleDbType.VarChar, ParameterDirection.Output);
        this.Database.ExecuteSqlCommand("BEGIN P_SID.SID_PGet(:io_SID); END;", parameter);
        var sid = parameter.Value as string;
    
        return sid;
    }
    

提交回复
热议问题