我开始使用StackExchange 迷你分析器,并希望将它与 oracle 数据库一起使用。
但是当我运行查询时抛出异常 -
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);
}
如何解决这个问题?