Exemple #1
0
        /// <summary>
        ///     Run query asynchronously.
        /// </summary>
        /// <param name="provider">
        ///     Query provider.
        /// </param>
        /// <param name="token">
        ///     The cancellation token that will be checked for stop reading.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///     The <paramref name="provider"/> argument has <c>null</c> value.
        /// </exception>
        /// <exception cref="QueryDbException">
        ///     Error occured during executing the query.
        /// </exception>
        public async Task RunAsync(DbQueryProvider provider, CancellationToken token = default)
        {
            if (provider == null)
            {
                throw new ArgumentNullException(nameof(provider));
            }

            object?[] args = MapIds(Parameters.ToArray());
            try
            {
                await provider.ReadAsync <string>(Id, Command ?? "", args, token).ConfigureAwait(false);
            }
            catch (Exception exp)
            {
                throw new QueryDbException(Id, Command, Parameters, exp);
            }
        }
Exemple #2
0
        /// <summary>
        ///     Run query and count records.
        /// </summary>
        /// <param name="provider">
        ///     Query provider.
        /// </param>
        /// <returns>
        ///     Record count.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        ///     The <paramref name="provider"/> argument has <c>null</c> value.
        /// </exception>
        /// <exception cref="QueryDbException">
        ///     Error occured during executing the query.
        /// </exception>
        public int?RunCount(DbQueryProvider provider)
        {
            if (provider == null)
            {
                throw new ArgumentNullException(nameof(provider));
            }

            object?[] args = MapIds(Parameters.ToArray());
            try
            {
                return(provider.Query(Id, Command, args, 1).Count());
            }
            catch (Exception exp)
            {
                throw new QueryDbException(Id, Command, Parameters, exp);
            }
        }
Exemple #3
0
        /// <summary>
        ///     Run query.
        /// </summary>
        /// <param name="provider">
        ///     Query provider.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///     The <paramref name="provider"/> argument has <c>null</c> value.
        /// </exception>
        /// <exception cref="QueryDbException">
        ///     Error occured during executing the query.
        /// </exception>
        public void Run(DbQueryProvider provider)
        {
            if (provider == null)
            {
                throw new ArgumentNullException(nameof(provider));
            }

            object?[] args = MapIds(Parameters.ToArray());
            try
            {
                provider.Read <string>(Id, Command ?? "", args);
            }
            catch (Exception exp)
            {
                throw new QueryDbException(Id, Command, Parameters, exp);
            }
        }
Exemple #4
0
        /// <summary>
        ///     Run query asynchronously.
        /// </summary>
        /// <param name="provider">
        ///     Query provider.
        /// </param>
        /// <param name="token">
        ///     The cancellation token that will be checked for stop reading.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///     The <paramref name="provider"/> argument has <c>null</c> value.
        /// </exception>
        /// <exception cref="QueryDbException">
        ///     Error occured during executing the query.
        /// </exception>
        public async Task <int?> RunCountAsync(DbQueryProvider provider, CancellationToken token = default)
        {
            if (provider == null)
            {
                throw new ArgumentNullException(nameof(provider));
            }

            object?[] args = MapIds(Parameters.ToArray());
            try
            {
                var i = 0;
                await foreach (object?[] _ in provider.QueryAsync(Id, Command ?? "", args, 1, token))
                {
                    ++i;
                }
                return(i);
            }
            catch (Exception exp)
            {
                throw new QueryDbException(Id, Command, Parameters, exp);
            }
        }