Ejemplo n.º 1
0
        public SaveResult SaveChanges(JObject saveBundle, TransactionSettings transactionSettings = null)
        {
            if (SaveWorkState == null || SaveWorkState.WasUsed)
            {
                InitializeSaveState(saveBundle);
            }

            transactionSettings = transactionSettings ?? BreezeConfig.Instance.GetTransactionSettings();
            try {
                if (transactionSettings.TransactionType == TransactionType.TransactionScope)
                {
                    var txOptions = transactionSettings.ToTransactionOptions();
                    using (var txScope = new TransactionScope(TransactionScopeOption.Required, txOptions)) {
                        OpenAndSave(SaveWorkState);
                        txScope.Complete();
                    }
                }
                else if (transactionSettings.TransactionType == TransactionType.DbTransaction)
                {
                    // this.OpenDbConnection();
                    using (IDbTransaction tran = BeginTransaction(transactionSettings.IsolationLevelAs)) {
                        try {
                            OpenAndSave(SaveWorkState);
                            tran.Commit();
                        } catch {
                            tran.Rollback();
                            throw;
                        }
                    }
                }
                else
                {
                    OpenAndSave(SaveWorkState);
                }
            } catch (EntityErrorsException e) {
                SaveWorkState.EntityErrors = e.EntityErrors;
                throw;
            } catch (Exception e2) {
                if (!HandleSaveException(e2, SaveWorkState))
                {
                    throw;
                }
            }
            finally {
                CloseDbConnection();
            }

            return(SaveWorkState.ToSaveResult());
        }
        /// <summary>
        /// See <see cref="Object.Equals(Object)"/>.
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(Object obj)
        {
            if (obj == null)
            {
                return(false);
            }
            TransactionSettings other = obj as TransactionSettings;

            if (other == null)
            {
                return(false);
            }
            return(other.IsolationLevel.Equals(this.IsolationLevel) &&
                   other.Timeout.Equals(this.Timeout) &&
                   other.TransactionType.Equals(this.TransactionType));
        }