首页 > 代码库 > EF CODEFIRST WITH ORACLE 存储过程

EF CODEFIRST WITH ORACLE 存储过程

EF  CODEFIRST WITH ORACLE

解决存储过程一直没找到解决方案

所以最后也没办法还是用了最基本的解决方案

采用Oracle.ManagedDataAccess提供的ADO基础访问类,不需要再次额外引用第三方类库了。

using Oracle.ManagedDataAccess.Client;

public object[] ExecuteProc(string procName, params DbParameter[] parms)
        {
            MyDbContext dbContext = this.GetDbContext(AccessMode.Write);
            using (var conn = new OracleConnection(dbContext.Database.Connection.ConnectionString))
            {
                List<DbParameter> outParms = parms.Where(p => p.Direction == System.Data.ParameterDirection.Output || p.Direction == System.Data.ParameterDirection.ReturnValue).ToList();
                OracleCommand command = new OracleCommand(procName);
                command.Connection = conn;
                command.CommandType = CommandType.StoredProcedure;

                command.Parameters.AddRange(parms);
                conn.Open();
                command.ExecuteNonQuery();

                command.Parameters.Clear();
                command.Dispose();
                conn.Close();
                object[] values = outParms.Select(r => r.Value).ToArray();
                return values;
            }
        }

调用

 BaseRepository resp = new BaseRepository();
            var p3 = resp.GetParameterOut("COUNT_ROW", System.Data.DbType.Int32, 4);
            object[] o = resp.ExecuteProc("PROC1", p3);
            var ss = p3.Value;

 

EF CODEFIRST WITH ORACLE 存储过程