I\'m currently using the Microsoft ADO.NET provider for Oracle (System.Data.OracleClient
). I\'m aware that it is certainly not the best Oracle provider availabl
Use indirection and inheritance! If you're performing data access through an abstract Database class, require the Database implementation handle parameter binding.
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;
}
}
Code based on the Data Access Application Block in the Enterprise Library.
I think you can create your own provider that uses the defaults you want to use. You could create that provider easily by inheriting all the classes from odp.net, just adjust some properties like BindByName.
The DbProviderfactory will create your classes instead of the normal odp.net classes.
As for the discontinuation of the Microsoft ADO .NET provider for Oracle :
ODP .NET took too much of my time already.