public async Task <T> ExecProcedureNonQuery <T>(ProcedureName procedureName, DbRequestToken token, params ProcedureParameter[] parameters) where T : struct
        {
            var dbParams = await GetDbParameters(procedureName, token, parameters);

            var result = await dbMediator.ExecuteProcedureNonQuery(procedureName, token, dbParams);

            return((T)Convert.ChangeType(result, typeof(T)));
        }
Exemple #2
0
        public async Task <int> ExecuteProcedureNonQuery(ProcedureName procedureName, DbRequestToken token, params DataBaseParameter[] parameters)
        {
            var command = token.Connection.CreateCommand();

            command.CommandType = CommandType.StoredProcedure;
            command.CommandText = procedureName.GetStringName();
            command.Transaction = token.Transaction;
            AddParamsToCommand(command, parameters);
            return(await command.ExecuteNonQueryAsync());
        }
Exemple #3
0
        public async Task <CommandResponse> ExecuteProcedure(ProcedureName procedureName, DbRequestToken token, params DataBaseParameter[] parameters)
        {
            var command = token.Connection.CreateCommand();

            command.CommandType = CommandType.StoredProcedure;
            command.CommandText = procedureName.GetStringName();
            command.Transaction = token.Transaction;
            AddParamsToCommand(command, parameters);
            var reader = await command.ExecuteReaderAsync();

            var resp = new CommandResponse();

            for (int i = 0; i < reader.FieldCount; i++)
            {
                resp.ColumnNames.Add(reader.GetName(i));
            }
            while (reader.Read())
            {
                var currentVals = new List <object>(reader.FieldCount);
                for (var i = 0; i < reader.FieldCount; ++i)
                {
                    currentVals.Add(reader[i]);
                }
            }
            return(resp);
        }
        private async Task <DataBaseParameter> GetDbParameter(ProcedureName procedureName, DbRequestToken token, ProcedureParameter parameter)
        {
            var dbParam = new DataBaseParameter(parameter);

            if (parameter.DbType.HasValue)
            {
                return(dbParam);
            }
            var procNameParam = new ProcedureParameter("procedureName", procedureName.GetStringName())
            {
                DbType = SqlDbType.NVarChar
            };
            var res = (await ExecProcedure <ProcedureParameterDescription>(ProcedureName.spInternalGetProcedureParameters, token, procNameParam)).Single();

            dbParam.DbType = (SqlDbType)Enum.Parse(typeof(SqlDbType), res.ToString());
            return(dbParam);
        }
        private async Task <DataBaseParameter[]> GetDbParameters(ProcedureName procedureName, DbRequestToken token, params ProcedureParameter[] parameters)
        {
            var result = new DataBaseParameter[parameters.Length];

            for (var i = 0; i < parameters.Length; ++i)
            {
                result[i] = await GetDbParameter(procedureName, token, parameters[i]);
            }
            return(result);
        }
        public async Task ExecuteProcedureNoResult(ProcedureName procedureName, DbRequestToken token, params ProcedureParameter[] parameters)
        {
            var dbParams = await GetDbParameters(procedureName, token, parameters);

            await dbMediator.ExecuteProcedureNonQuery(procedureName, token, dbParams);
        }
        public async Task <IEnumerable <T> > ExecProcedure <T>(ProcedureName procedureName, DbRequestToken token, params ProcedureParameter[] parameters) where T : new()
        {
            var dbParams = await GetDbParameters(procedureName, token, parameters);

            var result = await dbMediator.ExecuteProcedure(procedureName, token, dbParams);

            return(result.MapToType <T>());
        }