/// <summary> /// Computes the min value of the target field in an asynchronous way. /// </summary> /// <typeparam name="TEntity">The type of the data entity.</typeparam> /// <typeparam name="TResult">The type of the result.</typeparam> /// <param name="connection">The connection object to be used.</param> /// <param name="field">The field to be minimized.</param> /// <param name="hints">The table hints to be used.</param> /// <param name="commandTimeout">The command timeout in seconds to be used.</param> /// <param name="transaction">The transaction to be used.</param> /// <param name="trace">The trace object to be used.</param> /// <param name="statementBuilder">The statement builder object to be used.</param> /// <returns>The min value of the target field.</returns> internal static Task <TResult> MinAllAsyncInternal <TEntity, TResult>(this IDbConnection connection, Field field, string hints = null, int?commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, IStatementBuilder statementBuilder = null) where TEntity : class { // Variables var request = new MinAllRequest(typeof(TEntity), connection, transaction, field, hints, statementBuilder); var param = (object)null; // Return the result return(MinAllInternalAsyncBase <TResult>(connection: connection, request: request, param: param, commandTimeout: commandTimeout, transaction: transaction, trace: trace)); }
/// <summary> /// Computes the min value of the target field in an asynchronous way. /// </summary> /// <typeparam name="TResult">The type of the result.</typeparam> /// <param name="connection">The connection object to be used.</param> /// <param name="tableName">The name of the target table to be used.</param> /// <param name="field">The field to be minimized.</param> /// <param name="hints">The table hints to be used.</param> /// <param name="commandTimeout">The command timeout in seconds to be used.</param> /// <param name="transaction">The transaction to be used.</param> /// <param name="trace">The trace object to be used.</param> /// <param name="statementBuilder">The statement builder object to be used.</param> /// <returns>The min value of the target field.</returns> internal static Task <TResult> MinAllAsyncInternal <TResult>(this IDbConnection connection, string tableName, Field field, string hints = null, int?commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, IStatementBuilder statementBuilder = null) { // Variables var request = new MinAllRequest(tableName, connection, transaction, field, hints, statementBuilder); // Return the result return(MinAllInternalAsyncBase <TResult>(connection: connection, request: request, param: null, commandTimeout: commandTimeout, transaction: transaction, trace: trace)); }
/// <summary> /// Minimizes the target field from all data of the database table. /// </summary> /// <param name="connection">The connection object to be used.</param> /// <param name="tableName">The name of the target table to be used.</param> /// <param name="field">The field to be maximumd.</param> /// <param name="hints">The table hints to be used. See <see cref="SqlServerTableHints"/> class.</param> /// <param name="commandTimeout">The command timeout in seconds to be used.</param> /// <param name="transaction">The transaction to be used.</param> /// <param name="trace">The trace object to be used.</param> /// <param name="statementBuilder">The statement builder object to be used.</param> /// <returns>The minimum value.</returns> internal static object MinAllInternal(this IDbConnection connection, string tableName, Field field, string hints = null, int?commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, IStatementBuilder statementBuilder = null) { // Variables var request = new MinAllRequest(tableName, connection, transaction, field, hints, statementBuilder); var param = (object)null; // Return the result return(MinAllInternalBase(connection: connection, request: request, param: param, commandTimeout: commandTimeout, transaction: transaction, trace: trace)); }
/// <summary> /// Computes the min value of the target field. /// </summary> /// <typeparam name="TResult">The type of the result.</typeparam> /// <param name="connection">The connection object to be used.</param> /// <param name="request">The actual <see cref="MinAllRequest"/> object.</param> /// <param name="param">The mapped object parameters.</param> /// <param name="commandTimeout">The command timeout in seconds to be used.</param> /// <param name="transaction">The transaction to be used.</param> /// <param name="trace">The trace object to be used.</param> /// <returns>The min value of the target field.</returns> internal static TResult MinAllInternalBase <TResult>(this IDbConnection connection, MinAllRequest request, object param, int?commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null) { // Variables var commandType = CommandType.Text; var commandText = CommandTextCache.GetMinAllText(request); var sessionId = Guid.Empty; // Before Execution if (trace != null) { sessionId = Guid.NewGuid(); var cancellableTraceLog = new CancellableTraceLog(sessionId, commandText, param, null); trace.BeforeMinAll(cancellableTraceLog); if (cancellableTraceLog.IsCancelled) { if (cancellableTraceLog.IsThrowException) { throw new CancelledExecutionException(commandText); } return(default);
/// <summary> /// Computes the min value of the target field in an asynchronous way. /// </summary> /// <typeparam name="TResult">The type of the result.</typeparam> /// <param name="connection">The connection object to be used.</param> /// <param name="request">The actual <see cref="MinAllRequest"/> object.</param> /// <param name="param">The mapped object parameters.</param> /// <param name="commandTimeout">The command timeout in seconds to be used.</param> /// <param name="transaction">The transaction to be used.</param> /// <param name="trace">The trace object to be used.</param> /// <param name="cancellationToken">The <see cref="CancellationToken"/> object to be used during the asynchronous operation.</param> /// <returns>The min value of the target field.</returns> internal static async Task <TResult> MinAllAsyncInternalBase <TResult>(this IDbConnection connection, MinAllRequest request, object param, int?commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, CancellationToken cancellationToken = default) { // Variables var commandType = CommandType.Text; var commandText = CommandTextCache.GetMinAllText(request); var sessionId = Guid.Empty; // Before Execution if (trace != null) { sessionId = Guid.NewGuid(); var cancellableTraceLog = new CancellableTraceLog(sessionId, commandText, param, null); trace.BeforeMinAll(cancellableTraceLog); if (cancellableTraceLog.IsCancelled) { if (cancellableTraceLog.IsThrowException) { throw new CancelledExecutionException(commandText); } return(default(TResult)); } commandText = (cancellableTraceLog.Statement ?? commandText); param = (cancellableTraceLog.Parameter ?? param); } // Before Execution Time var beforeExecutionTime = DateTime.UtcNow; // Actual Execution var result = await ExecuteScalarAsyncInternal <TResult>(connection : connection, commandText : commandText, param : param, commandType : commandType, cacheKey : null, cacheItemExpiration : null, commandTimeout : commandTimeout, transaction : transaction, cache : null, cancellationToken : cancellationToken, entityType : request.Type, dbFields : await DbFieldCache.GetAsync(connection, request.Name, transaction, true, cancellationToken), skipCommandArrayParametersCheck : true); // After Execution if (trace != null) { trace.AfterMinAll(new TraceLog(sessionId, commandText, param, result, DateTime.UtcNow.Subtract(beforeExecutionTime))); } // Result return(result); }
/// <summary> /// Computes the min value of the target field. /// </summary> /// <param name="connection">The connection object to be used.</param> /// <param name="request">The actual <see cref="MinAllRequest"/> object.</param> /// <param name="param">The mapped object parameters.</param> /// <param name="commandTimeout">The command timeout in seconds to be used.</param> /// <param name="transaction">The transaction to be used.</param> /// <param name="trace">The trace object to be used.</param> /// <returns>The min value of the target field.</returns> internal static object MinAllInternalBase(this IDbConnection connection, MinAllRequest request, object param, int?commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null) { // Variables var commandType = CommandType.Text; var commandText = CommandTextCache.GetMinAllText(request); var sessionId = Guid.Empty; // Before Execution if (trace != null) { sessionId = Guid.NewGuid(); var cancellableTraceLog = new CancellableTraceLog(sessionId, commandText, param, null); trace.BeforeMinAll(cancellableTraceLog); if (cancellableTraceLog.IsCancelled) { if (cancellableTraceLog.IsThrowException) { throw new CancelledExecutionException(commandText); } return(default(int)); } commandText = (cancellableTraceLog.Statement ?? commandText); param = (cancellableTraceLog.Parameter ?? param); } // Before Execution Time var beforeExecutionTime = DateTime.UtcNow; // Actual Execution var result = ExecuteScalarInternal(connection: connection, commandText: commandText, param: param, commandType: commandType, commandTimeout: commandTimeout, transaction: transaction, skipCommandArrayParametersCheck: true); // After Execution if (trace != null) { trace.AfterMinAll(new TraceLog(sessionId, commandText, param, result, DateTime.UtcNow.Subtract(beforeExecutionTime))); } // Result return(result); }
/// <summary> /// /// </summary> /// <param name="request"></param> /// <returns></returns> internal static string GetMinAllText(MinAllRequest request) { if (cache.TryGetValue(request, out var commandText) == false) { var statementBuilder = EnsureStatementBuilder(request.Connection, request.StatementBuilder); commandText = statementBuilder.CreateMinAll(new QueryBuilder(), request.Name, request.Field, request.Hints); cache.TryAdd(request, commandText); } return(commandText); }