Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Oct 02, 2012 09:44 AM by SarmadAhsan
May 15, 2012 09:02 PM|LINK
In a MVC 3 project that use EF, when I try to add a new controller in Visual Studio 2010, I receive the error:
"An item with the same key has already been added". I've found many post in internet, all related with entity navigation properties problems. In most cases deleting the navigation properties (if you don't need them!) both
in conceptual model than in store model, solves the problem. In my case I need that navigation properties and I'd like to know if it is a known bug or not.
The db is very big, but I've succesfully replicated the problem and zipped at the following url:
Open the visual studio solution. Navigate to ahr.web project.
Right click controllers and then add new Controller.
Select xxxART_ICOL entity, and for the context testdbEntities.
Click Add and you'll receive the error.
May 22, 2012 08:43 AM|LINK
Someone collect this issue and list the solution, you can refer it from here:
Hope this helpful
May 23, 2012 07:12 AM|LINK
I've already tried to remove the entities from the model and re-adding them, but with no luck.
I've linked the project in the first post.
May 24, 2012 12:13 PM|LINK
Check ur Designer class may be u'll find some duplicate entities there .
May 27, 2012 12:12 PM|LINK
In the first post I've attached the example that reproduces the error. I haven't found any duplicate in the model.
Anyone can tell me if it is a known bug or not?
Jun 15, 2012 04:08 PM|LINK
Can you give me an exemple of duplicate entities or key ?
Jun 15, 2012 09:57 PM|LINK
I've posted the url of the example in the previous posts,
In my opinion is a bug of the auto-scaffolding of the view
Oct 02, 2012 09:44 AM|LINK
I fixed the issue in your application by making the relation between xxxART_ICOL and xxxNOT_ARTI a 1...1 relationship. you can do this by right clicking on the relation line in the .edmx file and going into properties and changing the End2 Multiplicity to
1 instead of 0..1. This issue arrises because the foreign key and the primary key in your table are the same columns. It is better to avoid mixing Foreign keys with primary keys