Skip to content

SqlBulkAsync throws error System.ArgumentException: Value does not fall within the expected range. #61

@dev-jlb

Description

@dev-jlb

This test case throws an exception.

public async Task BulkNotWorking()
 {
     var data = new List<Scenario>()
     {
         new Scenario { Id = -3, Name = "test1", PeriodYear = 2023,  },
         new Scenario { Id = -4, Name = "test1", PeriodYear = 2023,  },
     };

     var query = @"insert into XXDM.ST_SCENARIO (ID, NAME, PERIOD_YEAR)
                   values (:ID, :NAME, :PERIOD_YEAR)";
     var mapping = new BulkMapping<Scenario>[]
     {
         new BulkMapping<Scenario>("ID", x => x.Id.Value),
         new BulkMapping<Scenario>("NAME", x => x.Name),
         new BulkMapping<Scenario>("PERIOD_YEAR", x => x.PeriodYear),
     };

     using var connection = client.GetConnection();
     await connection.SqlBulkAsync(query, data, mapping).ConfigureAwait(false);
 }

If I add appropriate OracleMappingType.xxxx to each of the mappings, like this, it works:

new BulkMapping("ID", x => x.Id.Value, OracleMappingType.Int32),

The exception is:

System.ArgumentException: Value does not fall within the expected range.

Stack Trace: 
OracleParameter.set_Value(Object value)
OracleDynamicParameters.AddParameters(IDbCommand command, Identity identity)
IDynamicParameters.AddParameters(IDbCommand command, Identity identity)
<>c__DisplayClass165_0.b__0(IDbCommand cmd, Object obj) line 1738
CommandDefinition.SetupCommand(IDbConnection cnn, Action2 paramReader) line 128 SqlMapper.TrySetupAsyncCommand(CommandDefinition command, IDbConnection cnn, Action2 paramReader) line 396
SqlMapper.ExecuteImplAsync(IDbConnection cnn, CommandDefinition command, Object param) line 642
BulkOperation.SqlBulkAsync[T](IDbConnection connection, String sql, IEnumerable1 objects, IEnumerable1 mapping, Nullable`1 cmdType, IDbTransaction transaction)
OracleScenarioRepository.BulkNotWorking() line 114
BulkTester.TestBulkInsert() line 18
ThreadOperations.ExecuteWithAbortSafety(Action action)

Finally, this issue was mentioned in https://github.com/DIPSAS/Dapper.Oracle/issues/49, but no suggestions or resolution was provided.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions