private static IsolationLevel SqlIsolationLevel(string isolationLevelKey) { if (string.IsNullOrEmpty(isolationLevelKey)) { return(DefaultIsolationLevel); } var isolationLevel = WebCallContext.GetData(isolationLevelKey); if (isolationLevel == null) { return(DefaultIsolationLevel); } var sqlIsolationLevel = (SqlIsolationLevel)isolationLevel; switch (sqlIsolationLevel) { case Infrastructure.SqlIsolationLevel.ReadCommitted: return(IsolationLevel.ReadCommitted); case Infrastructure.SqlIsolationLevel.Snapshot: return(IsolationLevel.Snapshot); case Infrastructure.SqlIsolationLevel.ReadUncommitted: return(IsolationLevel.ReadUncommitted); default: return(DefaultIsolationLevel); } }
public void Commit() { var transaction = (SqlTransaction)WebCallContext.GetData(TransactionKey); if (transaction != null) { // DomainEvents.Raise(new BeforeCommit()); transaction.Commit(); //DomainEvents.Raise(new AfterCommit()); } }
private static SqlTransaction Transaction(string connectionKey, string transactionKey) { var transaction = WebCallContext.GetData(transactionKey); if (transaction == null) { OpenSqlConnection(connectionKey, transactionKey); transaction = WebCallContext.GetData(transactionKey); } return((SqlTransaction)transaction); }
private static SqlConnection SqlConnection(string connectionKey) { var sqlConnection = WebCallContext.GetData(connectionKey); if (sqlConnection == null) { throw new Exception("No sql connection available"); } var connection = (SqlConnection)sqlConnection; return(connection); }
public SqlConnectionContext(SqlConnectionType connectiontype, SqlIsolationLevel sqlIsolationLevel) { lock (LockObject) { if (WebCallContext.GetData(ConnectionKey) == null) { WebCallContext.SetData(ConnectionKey, new SqlConnection(ConnectionString)); WebCallContext.SetData(IsolationLevelKey, sqlIsolationLevel); } else { throw new Exception("There is already a sql connection"); } } }