Migration : An item with the same key has already been added
See original GitHub issueWith the rc1 and rc2 the migration generate an error “An item with the same key has already been added”, the problem is that the message not indicate the code which throw the exception.
System.ArgumentException: An item with the same key has already been added.
at System.ThrowHelper.ThrowArgumentException (ExceptionResource resource) <0x7f064a680550 + 0x00021> in <filename unknown>:0
at System.Collections.Generic.Dictionary`2[TKey,TValue].Insert (System.Collections.Generic.TKey key, System.Collections.Generic.TValue value, Boolean add) <0x7f064a500a30 + 0x00168> in <filename unknown>:0
at System.Collections.Generic.Dictionary`2[TKey,TValue].Add (System.Collections.Generic.TKey key, System.Collections.Generic.TValue value) <0x7f064a4ffbe0 + 0x0001b> in <filename unknown>:0
at Microsoft.Data.Entity.Migrations.Design.CSharpMigrationOperationGenerator.Generate (Microsoft.Data.Entity.Migrations.Operations.CreateTableOperation operation, Microsoft.Data.Entity.Internal.IndentedStringBuilder builder) <0x423a9000 + 0x003c5> in <filename unknown>:0
at (wrapper dynamic-method) System.Object:CallSite.Target (System.Runtime.CompilerServices.Closure,System.Runtime.CompilerServices.CallSite,Microsoft.Data.Entity.Migrations.Design.CSharpMigrationOperationGenerator,object,Microsoft.Data.Entity.Internal.IndentedStringBuilder)
at Microsoft.Data.Entity.Migrations.Design.CSharpMigrationOperationGenerator.Generate (System.String builderName, IReadOnlyList`1 operations, Microsoft.Data.Entity.Internal.IndentedStringBuilder builder) <0x42358cb0 + 0x001fc> in <filename unknown>:0
at Microsoft.Data.Entity.Migrations.Design.CSharpMigrationsGenerator.GenerateMigration (System.String migrationNamespace, System.String migrationName, IReadOnlyList`1 upOperations, IReadOnlyList`1 downOperations) <0x42354f90 + 0x004c0> in <filename unknown>:0
at Microsoft.Data.Entity.Migrations.Design.MigrationsScaffolder.ScaffoldMigration (System.String migrationName, System.String rootNamespace, System.String subNamespace) <0x4231a670 + 0x006cf> in <filename unknown>:0
at Microsoft.Data.Entity.Design.MigrationsOperations.AddMigration (System.String name, System.String outputDir, System.String contextType) <0x42265e50 + 0x0011e> in <filename unknown>:0
at Microsoft.Data.Entity.Commands.Program+Executor+<>c__DisplayClass6_0.<AddMigration>b__0 () <0x41dd3840 + 0x00034> in <filename unknown>:0
at Microsoft.Data.Entity.Commands.Program+Executor.Execute (System.Action action) <0x41dd37b0 + 0x00028> in <filename unknown>:0
An item with the same key has already been added.
The entities are generated correctly with beta8.
But now apparently the migration implement automatically the discriminator in the whole of entities, that’s what i see when execute an action with loading entities on the old table with a hierarchy. I use a base class with the common columns that is inherited by the others, and perhaps EF want to generate a table with the base class to respect the TPH and which will contain all entities by default, before only the entity with an explicit discriminator with the fluent api was generated and the other entities have the hierarchy into the table with the name of derived class.
An another issue to refer to this message #2170
Issue Analytics
- State:
- Created 8 years ago
- Comments:12 (3 by maintainers)
Top GitHub Comments
In my case it was caused by duplicit IDbContextFactory<MyDbContext> implementation (twice, in 2 different files).
Oh sorry, I was closing it because it was a duplicate of #3061. #3061 will stay open until it’s fixed.