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' 中的标识列插入显式值。

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

 

解决办法:

在Id头上添加一个特性

 [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
  [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
  public int IDZ { get; set; }

 

相关文章:

  • 2022-01-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-11
猜你喜欢
  • 2021-09-04
  • 2021-07-05
  • 2021-12-13
  • 2022-02-15
相关资源
相似解决方案