Error when adding parameter to command in IDbCommandInterceptor.ReaderExecuting
Posted: Wed 07 Aug 2013 06:58
I tried to use IDbCommandInterceptor (https://entityframework.codeplex.com/wi ... terception).
I wanted to change the command
public void ReaderExecuting(DbCommand command, DbCommandInterceptionContext<DbDataReader> interceptionContext)
{
command.CommandText = command.CommandText + " OR Extent1.BookId = :p1";
var parameter = command.CreateParameter();
parameter.ParameterName = "p1";
parameter.DbType = DbType.Int64;
parameter.Value = 2;
command.Parameters.Add(parameter);
}
And it throw exception
Object reference not set to an instance of an object
I think it is because the parameter in command.Parameters has a type Devart.Data.Oracle.Entity.m (internal class), and the parameter type from command.CreateParameter() is Devart.Data.Oracle.OracleParameter?
How can i add a parameter to a command?
I wanted to change the command
public void ReaderExecuting(DbCommand command, DbCommandInterceptionContext<DbDataReader> interceptionContext)
{
command.CommandText = command.CommandText + " OR Extent1.BookId = :p1";
var parameter = command.CreateParameter();
parameter.ParameterName = "p1";
parameter.DbType = DbType.Int64;
parameter.Value = 2;
command.Parameters.Add(parameter);
}
And it throw exception
Object reference not set to an instance of an object
I think it is because the parameter in command.Parameters has a type Devart.Data.Oracle.Entity.m (internal class), and the parameter type from command.CreateParameter() is Devart.Data.Oracle.OracleParameter?
How can i add a parameter to a command?