Ejemplo n.º 1
0
        public void TestContext([IncludeDataSources(
                                     ProviderName.SqlServer2008, ProviderName.SqlServer2012,
                                     ProviderName.SqlServer2014, ProviderName.SapHana)]
                                string context)
        {
            var ctx = new DataContext(context);

            ctx.GetTable <Person>().ToList();

            ctx.KeepConnectionAlive = true;

            ctx.GetTable <Person>().ToList();
            ctx.GetTable <Person>().ToList();

            ctx.KeepConnectionAlive = false;

            using (var tran = new DataContextTransaction(ctx))
            {
                ctx.GetTable <Person>().ToList();

                tran.BeginTransaction();

                ctx.GetTable <Person>().ToList();
                ctx.GetTable <Person>().ToList();

                tran.CommitTransaction();
            }
        }
Ejemplo n.º 2
0
 private void EnsureTransaction()
 {
     if (transaction == null)
     {
         transaction = this.BeginTransaction(false);
     }
 }
Ejemplo n.º 3
0
        public void TestContext()
        {
            var ctx = new DataContext("Sql2008");

            ctx.GetTable <Person>().ToList();

            ctx.KeepConnectionAlive = true;

            ctx.GetTable <Person>().ToList();
            ctx.GetTable <Person>().ToList();

            ctx.KeepConnectionAlive = false;

            using (var tran = new DataContextTransaction(ctx))
            {
                ctx.GetTable <Person>().ToList();

                tran.BeginTransaction();

                ctx.GetTable <Person>().ToList();
                ctx.GetTable <Person>().ToList();

                tran.CommitTransaction();
            }
        }
Ejemplo n.º 4
0
 protected void Application_Error(object sender, EventArgs e)
 {
     if (DataContextTransaction != null)
     {
         DataContextTransaction.Rollback();
         DataContextTransaction.Dispose();
         DataContextTransaction = null;
     }
 }
Ejemplo n.º 5
0
        public void Commit()
        {
            if (this.transaction != null)
            {
                transaction.CommitTransaction();
            }

            this.transaction = null;
        }
Ejemplo n.º 6
0
        private static void CommitAndCloseDatabaseIfNecessary()
        {
            var dataContext = DataContextSimple;

            if (dataContext != null)
            {
                dataContext.SaveChanges();
                if (DataContextTransaction != null)
                {
                    DataContextTransaction.Commit();
                    DataContextTransaction.Dispose();
                }

                dataContext.Dispose();
                DataContextSimple = null;
            }
        }