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)


- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 更改自动增量起始编号? 2021-01-01
- SQL 临时表问题 2022-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01