Unable to cast object of type 'StackExchange.Profiling.Data.ProfiledDbCommand' to type 'Oracle.ManagedDataAccess.Client.OracleCommand'。
创建新的连接:
this._oracleConnection = new OracleConnection(ConnectionString.Oracle);
this._dbConnection = new StackExchange.Profiling.Data.ProfiledDbConnection(this._oracleConnection, MiniProfiler.Current);
方法中,我运行查询:
private long InsertData(SomeModel model, long someId, DbConnection conn)
{
OraDynamicParams insrtParams = this.GetSomeParams(model);
insrtParams.Add("a_some_id", someId);
insrtParams.Add("cur_OUT", dbType: OracleDbType.RefCursor, direction: ParameterDirection.Output);
dynamic res = conn.Query("SOME_CRUD.INSERT_PROC", insrtParams, commandType: CommandType.StoredProcedure).First();
//...
}
注: OraDynamicParams很简单,就是从SqlMapper.IDynamicParameters继承的类。
在下面的方法抛出异常时,试图转换为OracleCommand:
void SqlMapper.IDynamicParameters.AddParameters(IDbCommand command, SqlMapper.Identity identity)
{
var oracmd = (OracleCommand)command; // exception!
this.AddParameters(oracmd, identity);
}
如何解决这一问题?
2016-08-02
Edgar