【发布时间】:2013-01-08 19:47:16
【问题描述】:
在以下链接上提出的问题也有一个很好的答案,但我的问题从那之后开始。
Using Transactions or SaveChanges(false) and AcceptAllChanges()?
我尝试了按照我的要求给出的代码如下
MyEntities context1 = new MyEntities();
...
...
// some code for changing the table data in Context 1.
...
MyEntities context1 = new MyEntities();
using (TransactionScope scope = new TransactionScope())
{
context1.SaveChanges(false); // LABEL 1
context2.SaveChanges(false); // LABEL 2
scope.Complete(); // LABEL 3
context1.AcceptAllChanges(); // LABEL 4
context2.AcceptAllChanges(); // LABEL 5
}
在标有 // LABEL 1 的行之前一切正常 但是在 // LABEL 2 线上它没有说 “底层提供商在 Open 上失败。”
注意:- 请注意 Context1、Context2 是相同类型的 2 个不同实例。
有人可以帮我解决这个问题吗?
【问题讨论】:
-
调试任何东西的第一步是查看完整的错误消息。查看内部异常。
标签: entity-framework transactionscope savechanges