When trying to bulk insert an entity that has a property with a nullable enum type the insertion crashes with an exception if that property has a null value.
This shouldn't happen because, well, a nullable property should be allowed to be null.
System.InvalidOperationException
Nullable object must have a value.
at lambda_method90(Closure, Object)
at PhenX.EntityFrameworkCore.BulkInsert.Metadata.ColumnMetadata.GetValue(Object entity, BulkInsertOptions options) in /home/eisfunke/repos/misc/PhenX.EntityFrameworkCore.BulkInsert/src/PhenX.EntityFrameworkCore.BulkInsert/Metadata/ColumnMetadata.cs:line 49
at PhenX.EntityFrameworkCore.BulkInsert.PostgreSql.PostgreSqlBulkInsertProvider.BulkInsert[T](Boolean sync, DbContext context, TableMetadata tableInfo, IEnumerable`1 entities, String tableName, IReadOnlyList`1 columns, PostgreSqlBulkInsertOptions options, CancellationToken ctk) in /home/eisfunke/repos/misc/PhenX.EntityFrameworkCore.BulkInsert/src/PhenX.EntityFrameworkCore.BulkInsert.PostgreSql/PostgreSqlBulkInsertProvider.cs:line 76
at PhenX.EntityFrameworkCore.BulkInsert.BulkInsertProviderBase`2.PerformBulkInsertAsync[T](Boolean sync, DbContext context, TableMetadata tableInfo, IEnumerable`1 entities, TOptions options, Boolean tempTableRequired, CancellationToken ctk) in /home/eisfunke/repos/misc/PhenX.EntityFrameworkCore.BulkInsert/src/PhenX.EntityFrameworkCore.BulkInsert/BulkInsertProviderBase.cs:line 151
at PhenX.EntityFrameworkCore.BulkInsert.BulkInsertProviderBase`2.BulkInsertReturnEntities[T](Boolean sync, DbContext context, TableMetadata tableInfo, IEnumerable`1 entities, TOptions options, OnConflictOptions`1 onConflict, CancellationToken ctk)+MoveNext() in /home/eisfunke/repos/misc/PhenX.EntityFrameworkCore.BulkInsert/src/PhenX.EntityFrameworkCore.BulkInsert/BulkInsertProviderBase.cs:line 48
at PhenX.EntityFrameworkCore.BulkInsert.BulkInsertProviderBase`2.BulkInsertReturnEntities[T](Boolean sync, DbContext context, TableMetadata tableInfo, IEnumerable`1 entities, TOptions options, OnConflictOptions`1 onConflict, CancellationToken ctk)+MoveNext() in /home/eisfunke/repos/misc/PhenX.EntityFrameworkCore.BulkInsert/src/PhenX.EntityFrameworkCore.BulkInsert/BulkInsertProviderBase.cs:line 71
at PhenX.EntityFrameworkCore.BulkInsert.BulkInsertProviderBase`2.BulkInsertReturnEntities[T](Boolean sync, DbContext context, TableMetadata tableInfo, IEnumerable`1 entities, TOptions options, OnConflictOptions`1 onConflict, CancellationToken ctk)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult()
at PhenX.EntityFrameworkCore.BulkInsert.Extensions.PublicExtensions.ExecuteBulkInsertReturnEntitiesCoreAsync[TEntity,TOptions](DbSet`1 dbSet, Boolean sync, IEnumerable`1 entities, Action`1 configure, OnConflictOptions`1 onConflict, CancellationToken ctk) in /home/eisfunke/repos/misc/PhenX.EntityFrameworkCore.BulkInsert/src/PhenX.EntityFrameworkCore.BulkInsert/Extensions/PublicExtensions.cs:line 30
at PhenX.EntityFrameworkCore.BulkInsert.Extensions.PublicExtensions.ExecuteBulkInsertReturnEntitiesCoreAsync[TEntity,TOptions](DbSet`1 dbSet, Boolean sync, IEnumerable`1 entities, Action`1 configure, OnConflictOptions`1 onConflict, CancellationToken ctk) in /home/eisfunke/repos/misc/PhenX.EntityFrameworkCore.BulkInsert/src/PhenX.EntityFrameworkCore.BulkInsert/Extensions/PublicExtensions.cs:line 30
at PhenX.EntityFrameworkCore.BulkInsert.Tests.TestHelpers.InsertWithStrategyAsync[T](TestDbContextBase dbContext, InsertStrategy strategy, List`1 entities, Action`1 configure, OnConflictOptions`1 onConflict) in /home/eisfunke/repos/misc/PhenX.EntityFrameworkCore.BulkInsert/tests/PhenX.EntityFrameworkCore.BulkInsert.Tests/TestHelpers.cs:line 61
at PhenX.EntityFrameworkCore.BulkInsert.Tests.Tests.Basic.BasicTestsBase`1.InsertEntities_WithNullableEnums(InsertStrategy strategy) in /home/eisfunke/repos/misc/PhenX.EntityFrameworkCore.BulkInsert/tests/PhenX.EntityFrameworkCore.BulkInsert.Tests/Tests/Basic/BasicTestsBase.cs:line 101
at Xunit.Sdk.TestInvoker`1.<>c__DisplayClass47_0.<<InvokeTestMethodAsync>b__1>d.MoveNext() in /_/src/xunit.execution/Sdk/Frameworks/Runners/TestInvoker.cs:line 259
--- End of stack trace from previous location ---
at Xunit.Sdk.ExecutionTimer.AggregateAsync(Func`1 asyncAction) in /_/src/xunit.execution/Sdk/Frameworks/ExecutionTimer.cs:line 48
at Xunit.Sdk.ExceptionAggregator.RunAsync(Func`1 code) in /_/src/xunit.core/Sdk/ExceptionAggregator.cs:line 90
I haven't yet attempted to find the actual root cause though.
When trying to bulk insert an entity that has a property with a nullable enum type the insertion crashes with an exception if that property has a null value.
This shouldn't happen because, well, a nullable property should be allowed to be null.
I wrote a reproducer test in this MR: #111
Stacktrace:
I haven't yet attempted to find the actual root cause though.