[ACCEPTED]-Entity Framework Core 3.1.6 Item With Same Key Has Already Been Added-entity-framework-core
In EF Core 6.0 I encountered this error 7 when executing
add-migration. I renamed a class, which 6 should cause a migration that renames the 5 table.
It did not work when I renamed the 4 class and all the properties at once, but 3 it did work when I renamed all properties 2 to their new names and then create the migration, and 1 rename the class after creating the migration.
That isn't likely a SQL Server related exception 24 (i.e. I get the impression that you're thinking 23 the exception is being thrown due to a SQL 22 duplicate key exception, akin to what you 21 would see if you tried to create multiple 20 rows with a duplicate PK and/or unique key/index 19 key). Were that the case, you'd be seeing 18 a different exception (likely a SqlException 17 or related).
That is most likely a C# exception bubbling 16 up from somewhere in EF or related, and 15 if I had to take a wild guess, my first 14 hunch would be that you are possibly getting 13 the "Assessor" column returned 12 multiple times from the result set returned 11 by the pr_ExecuteFacilityQCRules stored 10 procedure. That's just a bit of a guess 9 however - a simple test would be to execute 8 the procedure in a SQL client and see the 7 columns returned. You'd typically see this 6 type of exception in C# by trying to add 5 multiple duplicate key names to a dictionary 4 or similar (i.e. myDictionary.Add(key)).
If 3 that is not the case, I think there'd need 2 to be a bit more info added to help diagnose 1 beyond making a guess.
I had the same issue while creating a migration 2 and solved it by upgrading from 6.0.1 to 1 6.0.3.
I received the same error in EF Core 6.0.
Updating 2 EF Core to 6.0.2 fixes the issue, and runs 1 the same migration with no issues.
More Related questions