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