报错信息: Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. See http://go.microsoft.com/fwlink/LinkId=472540 for information on
报错信息:Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. See http://go.microsoft.com/fwlink/?LinkId=472540 for information on understanding and handling optimistic concurrency exceptions.
参考资料:
https://stackoverflow.com/questions/1836173/entity-framework-store-update-insert-or-delete-statement-affected-an-unexpec
原因:主键id未设置自增,导致插入失败。
解决方案:表的主键id设置自增。
mysql设置方式:在表上右键-->设计表-->选中主键id-->勾选即可。
sqlserver设置方式:在表上右键-->设计表-->选中主键id-->双击“(是标识)”的值,改为是,标识增量和标识种子设置为1即可。
以上这篇EF(EntityFramework) 插入或更新数据报错的解决方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持每日运维。