EF SqlException: 当 IDENTITY_INSERT 设置为 OFF 时,不能为表 'Pic_Image' 中的标识列插入显式值。

EF插入数据时,表中的Id自增,导致数据插入数据报错。

System.Data.Entity.Infrastructure.DbUpdateException:“An error occurred while updating the entries. See the inner exception for details

SqlException: 当 IDENTITY_INSERT 设置为 OFF 时,不能为表 'Pic_Image' 中的标识列插入显式值。

解决办法:

在Id头上添加一个特性

 [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
  [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
  public int IDZ { get; set; }
原文地址:https://www.cnblogs.com/youmingkuang/p/12354547.html