2016-08-02 11 views
0

StackExchange mini profiler을 사용하기 시작했으며 Oracle 데이터베이스와 함께 사용하려고했습니다.
그러나 쿼리를 실행할 때 예외가 throw됩니다.
ProfiledDbCommand에서 OracleCommand 매개 변수를 검색하는 방법

Unable to cast object of type 'StackExchange.Profiling.Data.ProfiledDbCommand' to type 'Oracle.ManagedDataAccess.Client.OracleCommand'. OraDynamicParams 단순히 SqlMapper.IDynamicParameters에서 상속 클래스 :

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(); 

    //... 
} 


나는 새 연결을 만들 수 있습니다.

void SqlMapper.IDynamicParameters.AddParameters(IDbCommand command, SqlMapper.Identity identity) 
{ 
    var oracmd = (OracleCommand)command; // exception! 
    this.AddParameters(oracmd, identity); 
} 

방법이 문제를 해결하려면 다음 시도는 OracleCommand 캐스팅 할 때 다음과 같은 방법으로

는 예외가 발생?

답변

0

내 문제의 해결책을 찾았습니다.

StackExchange.Profiling.Data.ProfiledDbCommand에는 이라는 유형이 있으며이 유형은 OracleCommand입니다. 여기에서 추가 된 모든 매개 변수를 검색 할 수 있습니다.

코드를 수정하면 다음과 같이 보입니다.

void SqlMapper.IDynamicParameters.AddParameters(IDbCommand command, SqlMapper.Identity identity) 
{ 
    // Checks if profiler is used, if it is, then retrieve `InternalCommand` property 
    dynamic oracmd = command is OracleCommand ? command : ((ProfiledDbCommand)command).InternalCommand; 
    this.AddParameters((OracleCommand)oracmd, identity); 
}