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; }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM