Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
dev-jlb opened this issue Mar 9, 2023 · 1 comment

Comments

@dev-jlb
Copy link

dev-jlb commented Mar 9, 2023

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.

@hel1e
Copy link
Contributor

hel1e commented May 11, 2023

This is a duplicate of Issue #55

hel1e added a commit that referenced this issue May 11, 2023
This is also a fix to #61: SqlBulkAsync throws error System.ArgumentException: Value does not fall within the expected range.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants