SubSonic2.2 SharedDbConnectionScope和TransactionScope事务混淆 [英] SubSonic2.2 SharedDbConnectionScope and TransactionScope Transaction Confusion

查看:99
本文介绍了SubSonic2.2 SharedDbConnectionScope和TransactionScope事务混淆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ARGH !!!

围绕SharedDbConnectionScope和TransactionScope对象似乎有点混乱,以使您可以将SubSonic查询包装在事务中.

There seems to be a little confusion surrounding the SharedDbConnectionScope and TransactionScope objects to enable wrapping your SubSonic queries within a transaction.

文档建议指定使用的SharedDbConnectionScope包裹在使用的TransactionScope周围...

The docs suggest specifying the using SharedDbConnectionScope wrapped around the using TransactionScope...

using(SharedDbConnectionScope scope = new SharedDbConnectionScope())
{
  using(TransactionScope ts = new TransactionScope())
  {
    // do something
    ts.Complete();
  }
}

这里还有另一个问题,例如 Subsonic:一起使用SharedDbConnectionScope TransactionScope似乎已损坏提示文档错误,并且两个对象应该相反...

Then other question here such as Subsonic: Using SharedDbConnectionScope together with TransactionScope seems to be broken suggest the docs are wrong and the two objects should be the other way around...

using(TransactionScope ts = new TransactionScope())
{
  using(SharedDbConnectionScope scope = new SharedDbConnectionScope())
  {
    // do something
    ts.Complete();
  }
}

但是看着源代码,我感到更加困惑.

But looking into the source code I am even more confused.

在SqlQuery.cs代码文件中,它具有许多ExecuteTransaction重载.例如...

In the SqlQuery.cs code file it has a number of ExecuteTransaction overloads. For example...

public static void ExecuteTransaction(List<SqlQuery> queries)
{
  using(SharedDbConnectionScope scope = new SharedDbConnectionScope())
  {
    using(TransactionScope ts = new TransactionScope())
    {
      foreach(SqlQuery q in queries)
        q.Execute();
    }
  }
}

嗯...有趣...匹配文档但是... ts.Complete()调用在哪里?

Umm... Interesting... Matches the docs but... Where's the ts.Complete() call?

那应该如何提交交易?据我所知,它将始终回滚.对于所有ExecuteTransaction重载来说都是相同的!

How is that supposed to commit the transaction? As far as I can see it will always rollback. And it is the same for all the ExecuteTransaction overloads!

但这是真正的踢腿...

But here is the real kicker...

在TransactionWithDtcOffTests.cs中,代码进行了一些不错的测试,除了它们以另一种方式设置了SharedDbConnectionScope和TransactionScope!

In the TransactionWithDtcOffTests.cs code has some nice tests except they have set up the SharedDbConnectionScope and TransactionScope around the other way!

using(TransactionScope ts = new TransactionScope())
{
  using(SharedDbConnectionScope connScope = new SharedDbConnectionScope())
  {
    // <snip />
  }
}

我没有机会运行SubSonic 2.2的测试,但我认为有人通过了测试.

I haven't had the opportunity to run the tests for SubSonic 2.2 but I assume someone has and they passed..

最后...

有人可以给我关于应该如何设置SubSonic2.2中的事务的明确答案吗?文档确实是错误的吗? ExecuteTransaction重载和测试的源代码是否与实际正确的方式对齐?

Can someone give me the definitive answer to how Transactions in SubSonic2.2 should be set up? Are the docs indeed wrong? Does the source for the ExecuteTransaction overloads and tests be aligned to whichever way is actually correct?

推荐答案

SharedConnectionScope(SCS)块必须位于TransactionScope(TS)内. SCS的目的是在可能的情况下防止将事务升级到MSDTC,因此将TS using块放在SCS using块内部对我来说意义不大. 无论如何,每个TS块都必须具有Complete()调用才能提交事务.

The SharedConnectionScope (SCS) block must be inside a TransactionScope (TS). The purpose of the SCS is to prevent escalating the transaction to the MSDTC if possible, so having the TS using block inside of a SCS using block makes little sense to me. In any case, every TS block must have a Complete() call for the transaction to be committed.

这篇关于SubSonic2.2 SharedDbConnectionScope和TransactionScope事务混淆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆