0

Anyone knows how to force odp.net bind parameters by name, using it with enterprise library? I know that exists BindParameterByName using OracleCommand, but I'm using odp.net with enterprise library and DbCommand.

tomrozb
  • 25,773
  • 31
  • 101
  • 122
thiago
  • 123
  • 1
  • 3
  • 10

1 Answers1

1

I think this and this posts can help.

First of them tell you to extend it by your self, like

public abstract class Database { private readonly DbProviderFactory factory;

protected Database(DbProviderFactory factory)
{
    this.factory = factory;
}

public virtual DbCommand CreateCommand(String commandText)
{
    return CreateCommand(CommandType.Text, commandText);
}

public virtual DbCommand CreateCommand(CommandType commandType, String commandText)
{
    DbCommand command = factory.CreateCommand();
    command.CommandType = commandType;
    command.Text = commandText;
    return command;
}

public virtual void BindParametersByName(DbCommand command)
{

}

} And choose to create an Oracle specific implementation that overrides default command creation or provides the option to bind parameters by name.

public class OracleDatabase : Database { public OracleDatabase() : base(OracleClientFactory.Instance) {

}

public override DbCommand CreateCommand(CommandType commandType, String commandText)
{
    DbCommand command = base.CreateCommand(commandType, commandText);
    BindParametersByName(command);
    return command;
}

public override void BindParametersByName(DbCommand command)
{
    ((OracleCommand)command).BindByName = true;
}

}

Community
  • 1
  • 1
evgenyl
  • 7,837
  • 2
  • 27
  • 32