報錯信息: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未設(shè)置自增,導(dǎo)致插入失敗。
解決方案:表的主鍵id設(shè)置自增。
mysql設(shè)置方式:在表上右鍵-->設(shè)計表-->選中主鍵id-->勾選即可。
sqlserver設(shè)置方式:在表上右鍵-->設(shè)計表-->選中主鍵id-->雙擊“(是標識)”的值,改為是,標識增量和標識種子設(shè)置為1即可。
以上這篇EF(EntityFramework) 插入或更新數(shù)據(jù)報錯的解決方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持錯新站長站。
新聞熱點
疑難解答
圖片精選