Beispiel #1
0
        public bool Commit()
        {
            try
            {
                bool flag = Context.SaveChanges() > 0;
                if (_transaction != null)
                {
                    _transaction.Commit();
                }
                return flag;
            }
            catch (DbEntityValidationException dvex)
            {
                var errors = dvex.EntityValidationErrors.SelectMany(m => m.ValidationErrors).Select(m => m.ErrorMessage);
                string message = "Throw DbEntityValidationException: ";
                message += string.Join(";", errors);
                LogDebug(message);
                //LogError(message);
                if (_transaction != null)
                {
                    _transaction.Rollback();
                }
                _dbContextProvider.ResetDbContext();

                return false;
            }
            catch (Exception ex)
            {
                string message = "Throw Exception When Committing To DB: ";
                message += ex.Message;
                LogDebug(message);
                //LogError(message);
                if (_transaction != null)
                {
                    _transaction.Rollback();
                }
                _dbContextProvider.ResetDbContext();

                return false;
            }
        }