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(); } }
private void EnsureTransaction() { if (transaction == null) { transaction = this.BeginTransaction(false); } }
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(); } }
protected void Application_Error(object sender, EventArgs e) { if (DataContextTransaction != null) { DataContextTransaction.Rollback(); DataContextTransaction.Dispose(); DataContextTransaction = null; } }
public void Commit() { if (this.transaction != null) { transaction.CommitTransaction(); } this.transaction = null; }
private static void CommitAndCloseDatabaseIfNecessary() { var dataContext = DataContextSimple; if (dataContext != null) { dataContext.SaveChanges(); if (DataContextTransaction != null) { DataContextTransaction.Commit(); DataContextTransaction.Dispose(); } dataContext.Dispose(); DataContextSimple = null; } }