MikaelEliasson / EntityFramework.Utilities

Provides extensions for EntityFramework that doesn't exist out of the box like delete and update by query and bulk inserts
443 stars 176 forks source link

An item with the same key has already been added. #108

Open jkavimandan opened 7 years ago

jkavimandan commented 7 years ago

Job Message: Main Message: An item with the same key has already been added. Main Message Stack Trace: at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource) at System.Collections.Generic.Dictionary2.Insert(TKey key, TValue value, Boolean add) at EntityFramework.Utilities.EfMappingFactory.GetMappingsForContext(DbContext context) at EntityFramework.Utilities.EFBatchOperation2 .InsertAll[TEntity](IEnumerable1 items, DbConnection connection, Nullable1 batchSize)

This error occurs intermittently, though no duplicate key is being passed to the InsertAll().

digital-synapse commented 7 years ago

+1 An item with the same key has already been added. at System.Collections.Generic.Dictionary2.Insert(TKey key, TValue value, Boolean add) at EntityFramework.Utilities.EFBatchOperation2.InsertAll[TEntity](IEnumerable1 items, DbConnection connection, Nullable1 batchSize)

Does anyone have any idea what might be causing this?

jkavimandan commented 7 years ago

I actually stopped usinf this utility. If you loop and add is still good. Didnt see any performance issues. Just do your own.

sebastian-ilari commented 7 years ago

+1 getting the followin stack trace when apparently trying to insert an empty collection:

System.ArgumentException: An item with the same key has already been added. at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource) at System.Collections.Generic.Dictionary``2.Insert(TKey key, TValue value, Boolean add) at EntityFramework.Utilities.EfMappingFactory.GetMappingsForContext(DbContext context) in D:\Projects\GSAP-X-API\src\Externals\EntityFramework.Utilities\MappingHelper.cs:line 312 at EntityFramework.Utilities.EFBatchOperation``2.InsertAll[TEntity](IEnumerable``1 items, DbConnection connection, Nullable``1 batchSize) in D:\Projects\GSAP-X-API\src\Externals\EntityFramework.Utilities\EFBatchOperation.cs:line 115

I couldn't reproduce the issue using integration tests. My current versions are:

EntityFramework = 6.1.3 EntityFramework.Utilities = 1.0.2.0

RudeySH commented 6 years ago

See #57. This is a concurrency issue that would have been fixed if #61 or #113 ever got merged. Unfortunately, this project hasn't been updated in a while. Check out my fork, it contains all the latest fixes.