Dapper.Oracle icon indicating copy to clipboard operation
Dapper.Oracle copied to clipboard

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

Open dev-jlb opened this issue 2 years ago • 1 comments

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<Scenario>("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.<GetCacheInfo>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.

dev-jlb avatar Mar 09 '23 22:03 dev-jlb

This is a duplicate of Issue #55

hel1e avatar May 11 '23 19:05 hel1e