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:
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
abunet
Member
10 Points
11 Posts
ASP.NET MVC3 Add Controller – An item with the same key has already been added
May 15, 2012 09:02 PM|LINK
HI,
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:
http://www.cnrservice.it/sites/default/files/ef-mvc-error.zip
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.
Help!
Thanks
Young Yang -...
All-Star
21343 Points
1818 Posts
Microsoft
Re: ASP.NET MVC3 Add Controller – An item with the same key has already been added
May 22, 2012 08:43 AM|LINK
Someone collect this issue and list the solution, you can refer it from here: http://forums.asp.net/t/1698139.aspx/1
Hope this helpful
Regards
Feedback to us
Develop and promote your apps in Windows Store
abunet
Member
10 Points
11 Posts
Re: ASP.NET MVC3 Add Controller – An item with the same key has already been added
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.
Thanks
suraj singh ...
Member
18 Points
11 Posts
Re: ASP.NET MVC3 Add Controller – An item with the same key has already been added
May 24, 2012 12:13 PM|LINK
Check ur Designer class may be u'll find some duplicate entities there .
abunet
Member
10 Points
11 Posts
Re: ASP.NET MVC3 Add Controller – An item with the same key has already been added
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.
http://www.cnrservice.it/sites/default/files/ef-mvc-error.zip
Anyone can tell me if it is a known bug or not?
Thanks
alexcoupal
Member
2 Points
1 Post
Re: ASP.NET MVC3 Add Controller – An item with the same key has already been added
Jun 15, 2012 04:08 PM|LINK
Can you give me an exemple of duplicate entities or key ?
abunet
Member
10 Points
11 Posts
Re: ASP.NET MVC3 Add Controller – An item with the same key has already been added
Jun 15, 2012 09:57 PM|LINK
I've posted the url of the example in the previous posts,
http://www.cnrservice.it/sites/default/files/ef-mvc-error.zip
In my opinion is a bug of the auto-scaffolding of the view
SarmadAhsan
Member
2 Points
1 Post
Re: ASP.NET MVC3 Add Controller – An item with the same key has already been added
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