Skip to content

Commit

Permalink
Fallback to PassParametersByName when BindByName is not available to …
Browse files Browse the repository at this point in the history
…support DevArt.
  • Loading branch information
danielmarbach committed Mar 1, 2024
1 parent b610ee0 commit cf0714c
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/SqlPersistence/Config/SqlDialect_Oracle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public abstract partial class SqlDialect
/// </summary>
public partial class Oracle : SqlDialect
{
volatile PropertyInfo bindByName;
volatile PropertyInfo parametersByNameProperty;

internal override void SetJsonParameterValue(DbParameter parameter, object value)
{
Expand Down Expand Up @@ -42,16 +42,19 @@ internal override CommandWrapper CreateCommand(DbConnection connection)
{
var command = connection.CreateCommand();

if (bindByName == null)
if (parametersByNameProperty == null)
{
var type = command.GetType();
bindByName = type.GetProperty("BindByName");
if (bindByName == null)
parametersByNameProperty = type.GetProperty("BindByName") ??
// someone might be using DevArt Oracle provider which uses PassParametersByName
type.GetProperty("PassParametersByName");
if (parametersByNameProperty == null)
{
throw new Exception($"Could not extract field 'BindByName' from '{type.AssemblyQualifiedName}'.");
throw new Exception($"Could not extract property 'BindByName' nor 'PassParametersByName' from '{type.AssemblyQualifiedName}'. The property is required to make sure the parameters passed to the commands can be passed by name and do not depend on the order they are added to the command.");
}
}
bindByName.SetValue(command, true);

parametersByNameProperty.SetValue(command, true);

return new CommandWrapper(command, this);
}
Expand Down

0 comments on commit cf0714c

Please sign in to comment.