Solution for: Store update, insert, or delete statement affected an unexpected number of rows (0)(解决方案:存储更新、插入或删除语句影响了意外的行数 (0))
问题描述
我为遇到异常的人找到了解决方案:
I found a solution for people who get an exception:
存储更新、插入或删除语句影响了意外的行数 (0).自加载实体以来,实体可能已被修改或删除.刷新 ObjectStateManager 条目.
但是,无论如何我有疑问.
But, anyway I have question.
我阅读了主题:实体框架:存储更新、插入、或删除语句影响了意外的行数 (0)."致VMAtm,罗伯特·哈维
I read topic: Entity Framework: "Store update, insert, or delete statement affected an unexpected number of rows (0)." To VMAtm, Robert Harvey
就我而言,我有例如表格文章:
In my case I had for example table articles:
Articles
------------
article_id
title
date_cr
date_mod
deleted
我有触发器:
create trigger articles_instead_of_insert
on articles instead of insert
as
SET NOCOUNT ON;
insert into articles(
article_id,
title,
date_cr,
date_mod,
deleted
)
select
user_id,
title,
isnull(date_cr, {fn NOW()}),
isnull(date_mod, {fn NOW()}),
isnull(deleted, 0)
from inserted;
go
当我删除此触发器时,我不会收到此异常.所以这个触发器是有问题的.现在我有一个问题——为什么?我应该做些什么吗?
When I delete this trigger then I dont get this exception. So this trigger is problem. And now I have a question - Why? Should I do something?
推荐答案
解决方案:
try {
context.SaveChanges();
} catch (OptimisticConcurrencyException) {
context.Refresh(RefreshMode.ClientWins, db.Articles);
context.SaveChanges();
}
这篇关于解决方案:存储更新、插入或删除语句影响了意外的行数 (0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:解决方案:存储更新、插入或删除语句影响了意外的行数 (0)


基础教程推荐
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- 带更新的 sqlite CTE 2022-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01