System.Data.UpdateException: A value shared across entities or associations is generated in more than one location. Check that mapping does not split an EntityKey to multiple store-generated columns
This Visual Studio 2010 RC bug is really causing grief. If you see the error message above, check your EDMX file. Visual Studio may have kindly inserted an extra
StoreGeneratedPattern="Identity"
into your EDMX file on a child table for the association back to the parent table.
For example, this …
<EntityType Name="ExceptionRecordData"> <Key> <PropertyRef Name="ExceptionDataUID" /> </Key> <Property Name="ExceptionDataUID" Type="bigint" Nullable="false" StoreGeneratedPattern="Identity" /> <Property Name="ExceptionUID" Type="bigint" Nullable="false" /> <Property Name="Name" Type="nvarchar" Nullable="false" MaxLength="32" /> <Property Name="Value" Type="nvarchar" Nullable="false" MaxLength="128" /> </EntityType>
becomes this … after a simple Update operation
<EntityType Name="ExceptionRecordData"> <Key> <PropertyRef Name="ExceptionDataUID" /> </Key> <Property Name="ExceptionDataUID" Type="bigint" Nullable="false" StoreGeneratedPattern="Identity" /> <Property Name="ExceptionUID" Type="bigint" Nullable="false" StoreGeneratedPattern="Identity" /> <Property Name="Name" Type="nvarchar" Nullable="false" MaxLength="32" /> <Property Name="Value" Type="nvarchar" Nullable="false" MaxLength="128" /> </EntityType>
Note how it has added an extra StoreGeneratedPattern=”Identity” on the ExceptionUID property. I hope this gets fixed soon.
If you experience this problem, here’s the link to up-vote it:- https://connect.microsoft.com/data/feedback/details/540058
Update: Microsoft has confirmed that this will be fixed in the released version of Visual Studio 2010 – see comments. Thanks!
about 1 year ago
I am sorry that this has been causing you grief. This has been fixed for VS 2010 RTM.
about 1 year ago
Thanks Craig for following up, glad to hear it’s fixed!
about 1 year ago
This has been fixed for the final release of VS2010.
- Danny
about 11 months ago
Is this bug valid for vs2008 sp1?
(Entity framework’s first version)
about 11 months ago
@kumar, it was a bug introduced part way through the development of EF4 and fixed before it was released, so I don’t think it applies to EF1.
about 8 months ago
It seems this issue still exists in 2010. Unless this is caused by another problem. I have the same hierarchy in my edmx
about 8 months ago
I have a hierarchy setup like this
Person << Client (Client inherits from person). Person.PersonId (PK)
Client.ClientId (PK, FK to PersonId)
Whoever setup the database set the Client.ClientId to Identity=true. So please disregard my last comment.