/// <summary>
        ///     <para>
        ///         Executes the given SQL against the database and returns the number of rows affected.
        ///     </para>
        ///     <para>
        ///         Note that this method does not start a transaction. To use this method with
        ///         a transaction, first call <see cref="BeginTransaction" /> or <see cref="UseTransaction" />.
        ///     </para>
        ///     <para>
        ///         Note that the current <see cref="ExecutionStrategy" /> is not used by this method
        ///         since the SQL may not be idempotent and does not run in a transaction. An ExecutionStrategy
        ///         can be used explicitly, making sure to also use a transaction if the SQL is not
        ///         idempotent.
        ///     </para>
        /// </summary>
        /// <param name="databaseFacade"> The <see cref="DatabaseFacade" /> for the context. </param>
        /// <param name="sql"> The SQL to execute. </param>
        /// <param name="parameters"> Parameters to use with the SQL. </param>
        /// <returns> The number of rows affected. </returns>
        public static int ExecuteSqlCommand(
            [NotNull] this DatabaseFacade databaseFacade,
            RawSqlString sql,
            [NotNull] IEnumerable <object> parameters)
        {
            Check.NotNull(databaseFacade, nameof(databaseFacade));
            Check.NotNull(sql, nameof(sql));
            Check.NotNull(parameters, nameof(parameters));

            var concurrencyDetector = databaseFacade.GetService <IConcurrencyDetector>();

            using (concurrencyDetector.EnterCriticalSection())
            {
                var rawSqlCommand = databaseFacade
                                    .GetRelationalService <IRawSqlCommandBuilder>()
                                    .Build(sql.Format, parameters);

                return(rawSqlCommand
                       .RelationalCommand
                       .ExecuteNonQuery(
                           databaseFacade.GetRelationalService <IRelationalConnection>(),
                           rawSqlCommand.ParameterValues));
            }
        }
 public static Task <int> ExecuteSqlCommandAsync(
     [NotNull] this DatabaseFacade databaseFacade,
     RawSqlString sql,
     [NotNull] params object[] parameters)
 => ExecuteSqlCommandAsync(databaseFacade, sql, (IEnumerable <object>)parameters);
 public static Task <int> ExecuteSqlCommandAsync(
     [NotNull] this DatabaseFacade databaseFacade,
     RawSqlString sql,
     CancellationToken cancellationToken = default)
 => ExecuteSqlCommandAsync(databaseFacade, sql, Enumerable.Empty <object>(), cancellationToken);