EF 调用oracle 存储过程

EF是如何调用的存储过程的,本人也是翻遍了个大网站,查阅了很多资料。终于解决了遇到的问题。

第一步:创建存储过程,在这里我就不多说了,不是文章说的重点。

declare

                                       O_VOUCHER_ACT_DEDUCTIONS  integer; 
                                       O_FREE_NUMBER             integer; 
                                       O_POINT_ACT_DEDUCTIONS    integer; 
                                       O_PAYMENTMONEY            integer; 
                                      O_ERROR_MESSAGE           integer;
                                      O_PAYNUM                  integer;
   begin
   p_cust_assets(10,710201,1,2,O_VOUCHER_ACT_DEDUCTIONS, O_FREE_NUMBER, O_POINT_ACT_DEDUCTIONS, O_PAYMENTMONEY, O_ERROR_MESSAGE, O_PAYNUM);
   
   dbms_output.put_line(O_VOUCHER_ACT_DEDUCTIONS);
     dbms_output.put_line(O_FREE_NUMBER);
      dbms_output.put_line(O_POINT_ACT_DEDUCTIONS);
       dbms_output.put_line(O_PAYMENTMONEY);
        dbms_output.put_line(O_ERROR_MESSAGE);
        dbms_output.put_line(O_PAYNUM);
        
  end;

 上面执行这个存储过程,是带有输出参数的。

第二步:调用存储过程,并输入参数

public void SelectToDBProcedure()
        {
            //参数第一种写法:
            //OracleParameter vip_con_custom_id = new OracleParameter(":i_vip_con_custom_id", OracleDbType.Int32, 710201, ParameterDirection.Input);     

            //第二种写法:
            //OracleParameter[] parameter = new OracleParameter[10];
            //parameter[0] = new OracleParameter(":i_vip_con_custom_id", OracleDbType.Int32, 710201, ParameterDirection.Input);

            //第三种写法:
            OracleParameter guest_type = new OracleParameter(":i_guest_type", OracleDbType.Int32);
            guest_type.Value = 10;
            guest_type.Direction = ParameterDirection.Input;

            OracleParameter vip_con_custom_id = new OracleParameter(":i_vip_con_custom_id", OracleDbType.Int32);
            vip_con_custom_id.Value = 710201;
            vip_con_custom_id.Direction = ParameterDirection.Input;

            OracleParameter ishascustomer = new OracleParameter(":i_ishascustomer", OracleDbType.Int32);
            ishascustomer.Value = 1;
            ishascustomer.Direction = ParameterDirection.Input;

            OracleParameter accompany_num = new OracleParameter(":i_accompany_num", OracleDbType.Int32);
            accompany_num.Value = 2;
            accompany_num.Direction = ParameterDirection.Input;

            OracleParameter O_VOUCHER_ACT_DEDUCTIONS = new OracleParameter("O_VOUCHER_ACT_DEDUCTIONS",OracleDbType.Int32);
            O_VOUCHER_ACT_DEDUCTIONS.OracleDbType = OracleDbType.Int32;
            O_VOUCHER_ACT_DEDUCTIONS.Direction = ParameterDirection.Output;

            OracleParameter O_FREE_NUMBER = new OracleParameter("O_FREE_NUMBER", OracleDbType.Int32);
            O_FREE_NUMBER.OracleDbType = OracleDbType.Int32;
            O_FREE_NUMBER.Direction = ParameterDirection.Output;

            OracleParameter O_POINT_ACT_DEDUCTIONS = new OracleParameter("O_POINT_ACT_DEDUCTIONS", OracleDbType.Int32);
            O_POINT_ACT_DEDUCTIONS.OracleDbType = OracleDbType.Int32;
            O_POINT_ACT_DEDUCTIONS.Direction = ParameterDirection.Output;

            OracleParameter O_PAYMENTMONEY = new OracleParameter("O_PAYMENTMONEY", OracleDbType.Int32);
            O_PAYMENTMONEY.OracleDbType = OracleDbType.Int32;
            O_PAYMENTMONEY.Direction = ParameterDirection.Output;

            OracleParameter O_ERROR_MESSAGE = new OracleParameter("O_ERROR_MESSAGE", OracleDbType.Int32);
            O_ERROR_MESSAGE.OracleDbType = OracleDbType.Int32;
            O_ERROR_MESSAGE.Direction = ParameterDirection.Output;

            OracleParameter O_PAYNUM = new OracleParameter("O_PAYNUM", OracleDbType.Int32);
            O_PAYNUM.OracleDbType = OracleDbType.Int32;
            O_PAYNUM.Direction = ParameterDirection.Output;

            var query = _db.Database.SqlQuery<CustAssetsModel>("begin p_cust_assets (:i_guest_type,:i_vip_con_custom_id,:i_ishascustomer,:i_accompany_num,:O_VOUCHER_ACT_DEDUCTIONS,:O_FREE_NUMBER,:O_POINT_ACT_DEDUCTIONS,:O_PAYMENTMONEY,:O_ERROR_MESSAGE,:O_PAYNUM); end;",
                guest_type, vip_con_custom_id, ishascustomer, accompany_num, O_VOUCHER_ACT_DEDUCTIONS, O_FREE_NUMBER, O_POINT_ACT_DEDUCTIONS, O_PAYMENTMONEY, O_ERROR_MESSAGE, O_PAYNUM);

          
            var result = query.ToList();

            //打印存储过程 返回参数
            Console.WriteLine("执行结果:{0}", O_PAYMENTMONEY.Value);
        }

 这样就OK了,可以输入返回参数结果值了。当然还有返回结果集的,还有带有多个结果集的存储过程;还处于摸索阶段,请大神指点,谢谢。

 

posted on 2017-05-17 14:15  IT小伙儿  阅读(1620)  评论(0编辑  收藏  举报