protected virtual void SetupMySqlOptions(DbConnection connection)
        {
            var optionsBuilder = new DbContextOptionsBuilder();

            optionsBuilder.UseMySql(connection, builder =>
            {
                // Set the actual server version from the open connection here, so we can
                // access it from IMySqlOptions later when generating the code for the
                // `UseMySql()` call.
                if (_options.ServerVersion.IsDefault)
                {
                    try
                    {
                        var mySqlConnection = (MySqlConnection)connection;
                        builder.ServerVersion(new ServerVersion(mySqlConnection.ServerVersion));
                    }
                    catch (InvalidOperationException)
                    {
                        // If we cannot determine the server version for some reason, just fall
                        // back on the latest one (the default).

                        // TODO: Output warning.
                    }
                }
            });

            if (Equals(_options, new MySqlOptions()))
            {
                _options.Initialize(optionsBuilder.Options);
            }
        }
Example #2
0
        protected virtual void SetupMySqlOptions(DbConnection connection)
        {
            // Set the actual server version from the open connection here, so we can
            // access it from IMySqlOptions later when generating the code for the
            // `UseMySql()` call.

            if (Equals(_options, new MySqlOptions()))
            {
                ServerVersion serverVersion;

                _logger.Logger.LogDebug($"No explicit {nameof(ServerVersion)} was set.");

                try
                {
                    serverVersion = ServerVersion.AutoDetect((MySqlConnection)connection);
                    _logger.Logger.LogDebug($"{nameof(ServerVersion)} '{serverVersion}' was automatically detected.");
                }
                catch (InvalidOperationException)
                {
                    // If we cannot determine the server version for some reason, just fall
                    // back on the latest MySQL version.
                    serverVersion = MySqlServerVersion.LatestSupportedServerVersion;

                    _logger.Logger.LogWarning($"No {nameof(ServerVersion)} could be automatically detected. The latest supported {nameof(ServerVersion)} will be used.");
                }

                _options.Initialize(
                    new DbContextOptionsBuilder()
                    .UseMySql(connection, serverVersion)
                    .Options);
            }
        }
Example #3
0
        private void SetupMySqlOptions(DbConnection connection)
        {
            var optionsBuilder = new DbContextOptionsBuilder();

            optionsBuilder.UseMySql(connection);

            _options.Initialize(optionsBuilder.Options);
            MySqlConnectionInfo.SetServerVersion((MySqlConnection)connection, _serviceProvider);
        }
Example #4
0
        private void SetupMySqlOptions(DbConnection connection)
        {
            var optionsBuilder = new DbContextOptionsBuilder();

            optionsBuilder.UseMySql(connection);

            if (Equals(_options, new MySqlOptions()))
            {
                _options.Initialize(optionsBuilder.Options);
            }
        }