Value cannot be null

Sep 18, 2014 at 1:31 AM
Edited Sep 18, 2014 at 1:32 AM
I am trying to setup bulk inserts for a project that is database first and I am running into "Value cannot be null" on version

Any help on how to fix would be appreciated.

Stack trace:

at System.RuntimeType.MakeGenericType(Type[] instantiation)
at EntityFramework.MappingAPI.Mappers.MapperBase.RegEntity(String typeFullName, String tableName, String schema) in c:\dev\EntityFramework.MappingAPI\trunk\src\EntityFramework.MappingAPI\Mappers\MapperBase.cs:line 248
at EntityFramework.MappingAPI.Mappers.MapperBase.MapEntity(String typeFullName, EdmType edmItem) in c:\dev\EntityFramework.MappingAPI\trunk\src\EntityFramework.MappingAPI\Mappers\MapperBase.cs:line 321
at EntityFramework.MappingAPI.Mappings.DbMapping..ctor(DbContext context) in c:\dev\EntityFramework.MappingAPI\trunk\src\EntityFramework.MappingAPI\Mappings\DbMapping.cs:line 80
at EntityFramework.MappingAPI.Extensions.MappingApiExtensions.Db(DbContext ctx, Type type) in c:\dev\EntityFramework.MappingAPI\trunk\src\EntityFramework.MappingAPI\Extensions\MappingApiExtensions.cs:line 51
at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable1 source, Func2 keySelector, Func2 elementSelector, IEqualityComparer1 comparer)
at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable1 source, Func2 keySelector, Func2 elementSelector)
at EntityFramework.BulkInsert.Helpers.MappedDataReader
1..ctor(IEnumerable1 enumerable, IEfBulkInsertProvider provider) in c:\dev\EntityFramework.BulkInsert\dev\Src\EntityFramework.BulkInsert\Helpers\MappedDataReader.cs:line 58
at EntityFramework.BulkInsert.Providers.EfSqlBulkInsertProviderWithMappedDataReader.Run[T](IEnumerable
1 entities, SqlTransaction transaction, BulkInsertOptions options) in c:\dev\EntityFramework.BulkInsert\dev\Src\EntityFramework.BulkInsert\Providers\EfSqlBulkInsertProviderWithMappedDataReader.cs:line 22
at EntityFramework.BulkInsert.Providers.ProviderBase2.Run[T](IEnumerable1 entities, BulkInsertOptions options) in c:\dev\EntityFramework.BulkInsert\dev\Src\EntityFramework.BulkInsert\Providers\ProviderBase.cs:line 108
at EntityFramework.BulkInsert.Extensions.BulkInsertExtension.BulkInsert[T](DbContext context, IEnumerable1 entities, SqlBulkCopyOptions sqlBulkCopyOptions, Nullable1 batchSize) in c:\dev\EntityFramework.BulkInsert\dev\Src\EntityFramework.BulkInsert\Extensions\BulkInsertExtension.cs:line 95
at EntityFramework.BulkInsert.Extensions.BulkInsertExtension.BulkInsert[T](DbContext context, IEnumerable1 entities, Nullable1 batchSize) in c:\dev\EntityFramework.BulkInsert\dev\Src\EntityFramework.BulkInsert\Extensions\BulkInsertExtension.cs:line 75
at ThirdParty.Library.Model.Entities.BulkInsert[T](IEnumerable`1 entities) in
Jul 2, 2015 at 2:08 AM
I have encountered the same problem. Were you able to resolve this issue? Is there something I need to do in the setup of my context or entities to support calling the BulkInsert?
Feb 26, 2016 at 10:46 PM
I encountered this too, and I found out the issue in my code-first project. I wrote a private subclass of one of my models which added a few properties. EF is able to find these private subclasses and will update the tables accordingly. BulkInsert, however, does not seem to support these classes, maybe it's not able to find them? As soon as this is the case, BulkInsert stops working entirely, even when inserting in unrelated tables.
Feb 28, 2016 at 10:47 PM
I discovered my problem was due to us using a legacy EDMX for database first model. I downloaded the BulkInsert codebase and debugged it to workout the elements of the EDMX that were no longer supported and I was able to solve this issue. From the exercise it became clear that BulkInsert relies on the EDMX rather than the POCO objects to determine the relationships. If you are having a similar issue I would suggest doing something similar.