Yesterday I came across an issue in the Entity Framework that really frustrated me for a couple of hours. I decided to leave it in peace until I was able to think clearly again. Today I went back to tackle the issue and I was finally able to find a solution to my problem.
Issue
I have three tables in place, one describing a user account, one describing an in installation and finally on describing the relation between them. Both the UserAccount table and the Installation table have a primary key set on an identity column named after the table (UserAccountId and InstallationId). The identity column is set to increment with 1 step at the insert of a row. The UserAccountInstallation table provides the mapping between user accounts and installations:

no rocket science here… the issue now is that whenever I try to insert a new installation object into the database, I gracefully receive a System.Data.UpdateException exception, stating in the message:
A value shared across entities or associations is generated in more than one location. Check that mapping does not split an EntityKey to multiple server-generated columns.
Solution
It seems that Visual Studio 2010 RC causes the problem. When creating/refreshing an entity model in the visual studio IDE, the columns that are marked as identity columns in the database are given the attribute “StoreGeneratedPattern” with value “identity” in the mapping:
UserAccount
<EntityType Name="UserAccount">
<Key>
<PropertyRef Name="UserAccountId" />
</Key>
<Property Name="UserAccountId" Type="int" Nullable="false" StoreGeneratedPattern="Identity" />
<Property Name="SyncServerId" Type="int" Nullable="false" StoreGeneratedPattern="Identity" />
<Property Name="Title" Type="nvarchar" MaxLength="8" />
<Property Name="FirstName" Type="nvarchar" Nullable="false" MaxLength="50" />
<Property Name="MiddleName" Type="nvarchar" MaxLength="50" />
<Property Name="LastName" Type="nvarchar" Nullable="false" MaxLength="50" />
<Property Name="Suffix" Type="nvarchar" MaxLength="10" />
<Property Name="Username" Type="nvarchar" Nullable="false" MaxLength="100" />
<Property Name="CultureCode" Type="nvarchar" Nullable="false" MaxLength="5" />
<Property Name="IsAdmin" Type="tinyint" Nullable="false" />
<Property Name="NameStyle" Type="bit" Nullable="false" />
<Property Name="EmailAddress" Type="nvarchar" MaxLength="50" />
<Property Name="EmailPromotion" Type="tinyint" Nullable="false" />
<Property Name="Phone" Type="nvarchar" MaxLength="25" />
<Property Name="PasswordHash" Type="varchar" Nullable="false" MaxLength="128" />
<Property Name="AccountNumber" Type="varchar" Nullable="false" MaxLength="10" StoreGeneratedPattern="Computed" />
<Property Name="ModifiedDate" Type="datetime" Nullable="false" />
</EntityType>
Installation
<EntityType Name="Installation">
<Key>
<PropertyRef Name="InstallationId" />
</Key>
<Property Type="Int32" Name="InstallationId" Nullable="false" a:StoreGeneratedPattern="Identity" xmlns:a="http://schemas.microsoft.com/ado/2009/02/edm/annotation" />
<Property Type="String" Name="Identifier" Nullable="false" MaxLength="38" FixedLength="true" Unicode="false" />
<Property Type="Byte" Name="IsActiveCode" Nullable="false" />
</EntityType>
UserAccountInstallation
<EntityType Name="UserAccountInstallation">
<Key>
<PropertyRef Name="UserAccountId" />
<PropertyRef Name="InstallationId" />
</Key>
<Property Name="UserAccountId" Type="int" Nullable="false" StoreGeneratedPattern="Identity" />
<Property Name="InstallationId" Type="int" Nullable="false" StoreGeneratedPattern="Identity" />
</EntityType>
The issue is caused because the columns in the mapping table are also given the same attribute and value, resulting in the database trying to auto-increment a column that is not configured to do so! The solution is to dive into the XML representation of the entity model and remove the attribute from the properties where it is not applicable.
UserAccountInstallation
<EntityType Name="UserAccountInstallation">
<Key>
<PropertyRef Name="UserAccountId" />
<PropertyRef Name="InstallationId" />
</Key>
<Property Name="UserAccountId" Type="int" Nullable="false" />
<Property Name="InstallationId" Type="int" Nullable="false" />
</EntityType>
Even further… my UserAccount table contains a reference to a another table that holds server configuration. This is a many-to-1 relationship as many user accounts can be member of the same server. The server is represented by its Id (auto-generated), in column SyncServerId… it seems that this column is also given the wrong attributes and I can fairly assume now that I will run again into the same issue when I try to include a new user account.
Is think the issue will be caused with every association created by the wizard where an endpoint is an identity column in a table.
In the mean time I found out that the problem is already brought to the attention of Microsoft: https://connect.microsoft.com/data/feedback/details/540058