Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded.

时间:2022-05-21 22:56:49

EF6进行Insert操作的时候提示错误

Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded.

1:确认model中是否外键关联问题

  解决方案:外键关联不要修改外键表的数据,可以暂是设置NotMapped或者外键model=null处理

2:确认model对应数据库表中id是否设置主键且主键自增长

  解决方案:数据库设置主键并主键自增长

 

这是目前我遇到的两种情况,如果还没有解决您的问题,请留言吧!