Entity Framework error: Cannot insert explicit value for identity column in table

前端 未结 8 1924
孤城傲影
孤城傲影 2020-11-27 07:09

I\'m getting this error on EF.

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

8条回答
  •  北荒
    北荒 (楼主)
    2020-11-27 07:28

    Try this:

    using System.ComponentModel.DataAnnotations.Schema;
    [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
    public decimal Identity_Col { get; set; }
    

    The Entity Framework class file adds these lines of code to the Identity column.

提交回复
热议问题