用户登录
用户注册

分享至

如何在数据上下文中使用事务

  • 作者: 让你无言以对
  • 来源: 51数据库
  • 2022-10-20

问题描述

我可以使用带有数据上下文的事务,以便在出错后回滚上下文的状态吗?如果是这样,它是如何工作的?

Can I use transactions with a datacontext, so that I can rollback the state of the context after an error? And if so, how does that work?

推荐答案

我一直在测试中使用它们 :)

I use them in testing all the time :)

try
{
  dc.Connection.Open();
  dc.Transaction = dc.Connection.BeginTransaction();

  dc.SubmitChanges();
}
finally
{
  dc.Transaction.Rollback();
}

更新

这将始终在事后回滚.我在测试中使用它.

This will ALWAYS rollback after the fact. I use this in testing.

软件
前端设计
程序设计
Java相关