日期:2014-05-20 浏览次数:21018 次
using (var dbtran = new TransactionScope(TransactionScopeOption.Required))
            {
                using (var t= new TestEntities())
                {
                     using (t.Connection.CreateConnectionScope())// EF Extension中的扩展方法,作用是open connection并在dispose里释放它
                    {                     
                            t.AddToTableA(t1);
                            t.SaveChanges();
                            var cmd = t.CreateStoreCommand("update form set xxx=xxx where formid=2", CommandType.Text);
          cmd.ExcuteNonQuery();
                            dbtran.Complete();
                      }
      }
    }