This project is read-only.


“The given key was not present in the dictionary.” when adding Association to Entities - all mapped to Views


When mapping entities and associations exclusively to SQL views, you get the a KeyNotFoundException. This does not occur when working with SQL tables.

See this question on StackOverflow for more information and a sample project:

file attachments

Closed Nov 18, 2013 at 10:20 PM by lukew
This regression no longer seems to be reproing for me. To get the fix, it is required that you update the EntityFramework.dll assembly in the common7 directory of your visual studio install as this is the copy that is reverenced by the designer. Installing the package from nuget alone will not get the fix for this bug.

the common7 directory for VS2013 (Dev12) is usually located at C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE likewise replace "12" with "11" for VS2012.


jcaubin wrote Nov 4, 2013 at 8:56 AM

I´ve the same issue.

moozzyk wrote Nov 4, 2013 at 7:04 PM

This is a regression in EF6 (view gen area). The attached model works fine in EF5. In EF6 we throw:

Unhandled Exception: System.Data.Entity.Core.EntityCommandCompilationException:
An error occurred while preparing the command definition. See the inner exception for details. ---> System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.

(the same appears in the designer when validating the model).

Full stack trace attached.

RoMiller wrote Nov 4, 2013 at 7:06 PM

Assigning to 6.0.2 since this is a regression

emilcicos wrote Nov 11, 2013 at 7:22 PM

commit c5f4416b97d796b7aa800fcc1d320558a01c55db

emilcicos wrote Nov 11, 2013 at 7:23 PM

... the commit above is wrong, should be:
commit 54f93671171fe491eaed12d87b8df40cfb9e6bad

bartekkk wrote Nov 16, 2013 at 3:31 PM

I've the same issue.
When the fix will be downloadable?

divega wrote Nov 18, 2013 at 5:05 PM

rnoack wrote Nov 18, 2013 at 5:39 PM

@divega I followed the link you posted to the nightly builds but when I add this source in Visual Studio it doesn't find any packages, also if you navigate directly to in the browser in the XML I don't see any packages listed which is suspicious...

But I have another question. Even if I could get it installed and it was working, do I really want to include the nightly build code into my production software release? Our software is in a really messy state right now on some developer machines who experimented with updating to EF6, but we can't commit our changes with a nightly build even if I could get it to install... what we really need is the final release.

patman0021 wrote Nov 18, 2013 at 6:12 PM

I followed the link and upgraded from EF 5 to EF 6.0.2 just fine. It updated the reference to the EntityFramework, added EntityFramework.SQLServer, removed the System.Data.Entity references etc.

However, I am still getting the "The given key was not present in the dictionary". Also, the version of EntityFramework shows in the properties. Shouldn't it show 6.0.2.<something>?

divega wrote Nov 18, 2013 at 6:16 PM

To your second question, no, we are not advising you to use our nightly builds in production. We are asking customers that have ran into problems to try the nightly builds to verify that they issues are solved. We are planning to release 6.0.2 official build to NuGet in a relatively short time.

divega wrote Nov 18, 2013 at 6:52 PM

@patman0021: the assembly version field will show (this is done for compatibility reasons) but other fields, such as descriptive version should show that it is 6.0.2. If you can confirm that you are getting the exception with the latest nightly build it can then be another slightly different case for which we have the same regression. Could you provide the full stack race and a repro?

bartekkk wrote Nov 18, 2013 at 8:06 PM

Thanks, downloaded from nigthly builds and for me works nice. Visual Studio displays the error but in runtime all works.

divega wrote Nov 18, 2013 at 9:21 PM

@Bartekkk: Thanks for confirming!

@patman0021: Bartekkk's comments just reminded me that the EF tooling uses its own version of the EF6 assembly to perform model validation (and other tasks). Until we release a refreshed version of the EF Designer containing 6.0.2 you will keep getting this same message in Visual Studio when the EDMX model is validated (e.g. at build time), even if you install the 6.0.2 NuGet package, but your application should work fine at runtime. Do you think it is possible that this is what is happening in your case?


patman0021 wrote Nov 18, 2013 at 11:15 PM

Very possible, especially since, like bartekkk mentioned, even though an error shows up in the error list, all of the files still get generated, and the application runs.

I'll wait until the 6.0.2 designer becomes available and test again.


divega wrote Nov 19, 2013 at 12:16 AM

@patman0021: Thanks for confirming!

moozzyk wrote Nov 19, 2013 at 1:41 AM

@patman0021: if you feel brave, overwrite the EntityFramework.dll located in %Program Files(x86)%\Microsoft Visual Studio 12.0\Common7\IDE with the one you got from nightly build (make sure to back-up the original one) and the EF designer should no longer show the error.

craigwagner wrote Dec 17, 2013 at 10:33 PM

FWIW, I was getting this same error with one of our EDMX's. I grabbed the EF 6.0.2 NuGet package and replaced the EntityFramework.dll in %Program Files(x86)%\Microsoft Visual Studio 12.0\Common7\IDE as suggested by moozzyk and it solved the problem.

moozzyk wrote Dec 17, 2013 at 11:20 PM

@craigwagner - thanks for confirming. EFTools 6.0.2 is now available for download so you can just upgrade tooling altogether. This post contains a link to download:

naveen_kumar wrote Dec 21, 2015 at 9:57 PM

I am using EF 6.1.3 and still facing the above issue. "The given key was not present in the dictionary"
I downloaded the package from NuGet which I am using. I tried to replace the EntityFramework dll which was already 6.0.2 but still no luck.

Attached are 2 stack track in same exception.