解决方案:存储更新,插入或删除语句影响意外数量的行(0) [英] 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,Robert Harvey
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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文