Exemple #1
0
        protected override TimeSpan?GetNextDelay(Exception lastException)
        {
            MySqlTrace.LogInformation(1, "Re");
            MySqlException   myex      = lastException as MySqlException;
            BackoffAlgorithm algorithm = null;

            if (!errorsToRetryOn.TryGetValue(myex.Number, out algorithm))
            {
                // This must never happen
                throw new InvalidOperationException(string.Format("Trying to retry for non transient exception number: {0}, message: {1}", myex.Number, myex.Message));
            }
            TimeSpan?ts = algorithm.GetNextDelay();

            if (ts != null)
            {
                MySqlTrace.LogInformation(1, string.Format("Retrying query for exception {0}", myex));
            }
            return(ts);
        }
Exemple #2
0
        public void TransactionTest()
        {
            using (var context = new SakilaLiteUpdateContext())
            {
                context.InitContext(false);
                MySqlTrace.LogInformation(9966, "EF Model CREATED");
            }

            using (MySqlConnection connection = new MySqlConnection(MySQLTestStore.GetContextConnectionString <SakilaLiteUpdateContext>()))
            {
                connection.Open();

                using (MySqlTransaction transaction = connection.BeginTransaction())
                {
                    MySqlCommand command = connection.CreateCommand();
                    command.CommandText = "DELETE FROM actor";
                    command.ExecuteNonQuery();

                    var options = new DbContextOptionsBuilder <SakilaLiteUpdateContext>()
                                  .UseMySQL(connection)
                                  .Options;

                    using (var context = new SakilaLiteUpdateContext(options))
                    {
                        context.Database.UseTransaction(transaction);
                        context.Actor.Add(new Actor
                        {
                            FirstName = "PENELOPE",
                            LastName  = "GUINESS"
                        });
                        context.SaveChanges();
                    }

                    transaction.Commit();
                }
            }
        }