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