public static IReadOnlyCollection <T> FindMany <T>(this IDbCommand command,
                                                    string commandText,
                                                    DatabaseCommandType commandType,
                                                    Func <IDataReader, T> mapFunction,
                                                    object?commandParameters = null)
 => command.FillCommand(commandText, commandType, commandParameters)
 .FindMany(mapFunction);
 public DatabaseCommand(string commandText,
                        DatabaseCommandType commandType,
                        T instance,
                        Func <T, object?>?commandParametersDelegate)
     : this(commandText, commandType, instance, DatabaseOperation.Unspecified, commandParametersDelegate)
 {
 }
Example #3
0
 /// <summary>
 /// Retorna um objeto de comando do banco de dados com base em um sql
 /// </summary>
 /// <param name="sql">Comando SQL</param>
 /// <param name="type">Tipo de comando</param>
 /// <returns></returns>
 public virtual IDbCommand GetCommand(string sql, DatabaseCommandType commandType = DatabaseCommandType.SQL)
 {
     if (commandType == DatabaseCommandType.PROCEDURE)
     {
         return(_db.GetStoredProcCommand(sql));
     }
     return(_db.GetSqlStringCommand(sql));
 }
    public void ToCommandType_Returns_Correct_Value(DatabaseCommandType input, CommandType expectedResult)
    {
        // Act
        var actual = input.ToCommandType();

        // Assert
        actual.Should().Be(expectedResult);
    }
 public static T?FindOne <T>(this IDbCommand command,
                             string commandText,
                             DatabaseCommandType commandType,
                             Func <IDataReader, T> mapFunction,
                             object?commandParameters = null)
     where T : class
 => command.FillCommand(commandText, commandType, commandParameters)
 .FindOne(mapFunction);
Example #6
0
    public void FillCommand_Fills_CommandType_Correctly(DatabaseCommandType dbCommandType, CommandType expectedCommandType)
    {
        // Arrange
        using var command = new DbCommand();

        // Act
        command.FillCommand("Test", dbCommandType);

        // Assert
        command.CommandType.Should().Be(expectedCommandType);
    }
 public SqlDatabaseCommand(string commandText,
                           DatabaseCommandType commandType,
                           DatabaseOperation operation = DatabaseOperation.Unspecified,
                           object?commandParameters    = null)
 {
     if (string.IsNullOrEmpty(commandText))
     {
         throw new ArgumentOutOfRangeException(nameof(commandText), "CommandText may not be null or empty");
     }
     CommandText       = commandText;
     CommandType       = commandType;
     Operation         = operation;
     CommandParameters = commandParameters;
 }
        public Database SetCommandType(DatabaseCommandType type)
        {
            switch (type)
            {
            case DatabaseCommandType.Text:
                CommandType = CommandType.Text;
                break;

            case DatabaseCommandType.StoredProcedureOrFunction:
                CommandType = CommandType.StoredProcedure;
                break;
            }

            return(this);
        }
 public DatabaseCommand(string commandText,
                        DatabaseCommandType commandType,
                        T instance,
                        DatabaseOperation operation,
                        Func <T, object?>?commandParametersDelegate)
 {
     if (string.IsNullOrEmpty(commandText))
     {
         throw new ArgumentOutOfRangeException(nameof(commandText), "CommandText may not be null or empty");
     }
     CommandText = commandText;
     CommandType = commandType;
     Operation   = operation;
     _instance   = instance;
     _commandParametersDelegate = commandParametersDelegate;
 }
 public static IDbCommand FillCommand(this IDbCommand command,
                                      string commandText,
                                      DatabaseCommandType commandType,
                                      object?commandParameters = null)
 {
     command.CommandText = commandText;
     command.CommandType = commandType.ToCommandType();
     if (commandParameters != null)
     {
         foreach (var param in commandParameters.ToExpandoObject())
         {
             command.AddParameter(param.Key, param.Value);
         }
     }
     return(command);
 }
Example #11
0
 public static CommandType ToCommandType(this DatabaseCommandType instance)
 => instance switch
 {