Transaction

May 31, 2010 at 8:03 AM

个人愚见:

        public void UsingTransaction(CallbackVoidHandler callback)
        {
            if (Scope<ConnectionContext>.Current != null)
            {
                callback();
                return;
            }
            NewTransaction(callback);
        }

应该为

 

public void UsingTransaction(CallbackVoidHandler callback)
        {
            if (Scope<ConnectionContext>.Current != null)
            {
                ConnectionContext cc = ConProvider;
                cc.BeginTransaction(IsolationLevel.ReadCommitted);
                try
                {
                    OnBeginTransaction();
                    callback();
                    cc.Commit();
                    OnCommittedTransaction();
                }
                catch
                {
                    try
                    {
                        cc.Rollback();
                    }
                    finally
                    {
                        OnTransactionError();
                    }
                    throw;
                }
                return;
            }
            NewTransaction(callback);
        }

-----------------

 

这样为了避免这样的情况
      DbEntry.NewConnection(()=>{

DbEntry.UsingTransaction(()=>{

...

这里就进不去NewTransaction了

...

个人愚见,如果有错,请海涵。。。

})

 

})
    

 

 

May 31, 2010 at 8:05 AM

就是Trasaction嵌套。。。

Coordinator
May 31, 2010 at 8:55 AM
Edited May 31, 2010 at 8:55 AM

DbEntry.NewConnection(()=>{

DbEntry.UsingTransaction(()=>{

这种用法就不科学啊。

Trasaction嵌套,应该是:

DbEntry.NewTransaction(()=>{

DbEntry.UsingTransaction(()=>{

或者:

DbEntry.NewTransaction(()=>{

DbEntry.NewTransaction(()=>{

May 31, 2010 at 11:52 AM

我的意思是为了避免有人在UsingTransaction外面再加入UsingConnection之类的。

当然不会刻意这么用。但是如果UsingTransaction碰巧在一个子函数里面,外面的人看不见也不知道,然后就在外面加上了UsingConnection之类的,就2了

 

May 31, 2010 at 11:59 AM
Edited May 31, 2010 at 12:00 PM

我个人愚见

NewTransaction

NewConnection

private

就可以

只用UsingXX.....刚发完就发现考虑不周,2个数据库的时候貌似new还是有用的