I just had this happen to me as well.
The problem turned out to be an association with end-keys, which were not all part of the primary key for that entity!
For instance, deep within my .edmx I had this association:
<AssociationSetMapping Name="Table1Table2" TypeName="MyModel.Table1Table2" StoreEntitySet="Table2">
<EndProperty Name="Table1">
<ScalarProperty Name="Table1Key" ColumnName="Table1Key" /></EndProperty>
<EndProperty Name="Table2">
<ScalarProperty Name="Table2Key" ColumnName="Table2Key" />
<ScalarProperty Name="Table2OtherColumn" ColumnName="Table2OtherColumn" />
</EndProperty></AssociationSetMapping>
and the definition of Table2 looks like this:
<EntityType Name="Table2">
<Key>
<PropertyRef Name="Table2Key" />
</Key>
<Property Name="Table2Key" Type="int" Nullable="false" />
<Property Name="Table2OtherColumn" Type="int" Nullable="false" />
...other properties...
</EntityType>
Notice that Table2OtherColumn
is in the EndProperty, but is not part of the actual key. Removing it from the EndProperty fixed the problem.
Note that Entity Framework 4 (Visual Studio 2010) can detect this problem at compile-time. Thus, if you are having serious trouble tracking down what table/property is causing this, just load your project into VS 2010 Express (after backing it up!) and try to compile.