2
votes

I'm new to EF, while trying to save changes to my context, I get the following error:

Cannot insert explicit value for identity column in table 'GroupMembers_New' when IDENTITY_INSERT is set to OFF.

The column on the DB is identity with autoincrement, on the edmx, id StoreGeneratedPattern is Identity and Default value is none, not sure why it keeps trying to insert 0 every time I try to save a group, any ideas?

thanks

1

1 Answers

2
votes

The StoreGeneratedPattern annotation must appear in two places in the EDMX file - in SSDL section...

<edmx:StorageModels>
  ...
  <EntityType Name="MyEntity">
    ...
    <Property Name="MyEntityID" Type="int" Nullable="false"
              StoreGeneratedPattern="Identity" />
    ...
  </EntityType>
  ...
</edmx:StorageModels>

...and in CSDL section as well:

<edmx:ConceptualModels>
  ...
  <EntityType Name="MyEntity">
    ...
    <Property Name="MyEntityID" Type="Int32" Nullable="false"
              annotation:StoreGeneratedPattern="Identity" />
    ...
  </EntityType>
  ...
</edmx:ConceptualModels>

Perhaps the reason for your problem is that the annotation is missing in one of the two places.