ef添加数据时出错 System.Data.Entity.Infrastructure.DbUpdateConcurrencyException”类型的异常

找半天才找到 ef添加数据时出错原因:数据库表中没有主键 ,就算表中有自增列 Added方法也会报错;

-        this._db.SaveChanges()  

 “this._db.SaveChanges()”引发了“System.Data.Entity.Infrastructure.DbUpdateConcurrencyException”类型的异常    int {System.Data.Entity.Infrastructure.DbUpdateConcurrencyException}

 

 

解决办法:添加一个主键列或者给某列加主键:可以是NEWID()随机函数 给默认值,不影响数据库结构,

posted @ 2016-12-20 16:33  阿Q啊  阅读(1049)  评论(0编辑  收藏  举报