IDENTITY_INSERT set to OFF cannot add data to table ‘… The identity column in ‘inserts an explicit value. Strangely, the add record method has always worked well and never failed. If something goes wrong, it’s an “attach or not attach” problem that only happens when you Update it. From the prompt, a value has been inserted into the identity column. So why does EF not recognize the identity column? It turned out that the EF did not recognize the field as an identity column because the EF generated the EF code and changed the field into an identity column in the database. In the.edmx file, look at the code, which describes the entity class as follows: \

        <EntityType Name="Status_Info">
          <Key>
            <PropertyRef Name="ID" />
          </Key>
          <Property Name="ID" Type="int" StoreGeneratedPattern="Identity" Nullable="false" />
          <Property Name="StatusID" Type="int" />
          <Property Name="Color" Type="nchar" MaxLength="10" />
        </EntityType>
Copy the code

\

It is clear whether a column is identified or not.

Lesson learned: Always refresh the EF code for database changes.