Ejemplo n.º 1
0
        public async Task ExecuteAsync(string connection, string sql, object parameters)
        {
            using (var c = new MySqlData.MySqlClient.MySqlConnection(connection))
            {
                _log.LogTrace <MySqlQuery>($"EXECUTE: {sql}. Parameters: {JsonConvert.SerializeObject(parameters)}");

                await c.OpenAsync();

                await c.ExecuteAsync(sql, parameters);

                await c.CloseAsync();
            }
        }
Ejemplo n.º 2
0
        public async Task <T> ExecuteScalarAsync <T>(string connection, string sql, object parameters)
        {
            T result = default;

            using (var c = new MySqlData.MySqlClient.MySqlConnection(connection))
            {
                _log.LogTrace <MySqlQuery>($"EXECUTE: {sql}. Parameters: {JsonConvert.SerializeObject(parameters)}");

                await c.OpenAsync();

                result = await c.ExecuteScalarAsync <T>(sql, parameters);

                await c.CloseAsync();
            }

            return(result);
        }
Ejemplo n.º 3
0
        public async Task <List <T> > GetAsync <T>(string connection, string sql, object parameters)
        {
            var result = new List <T>();

            //var test = new MySql.Data.MySqlClient()
            using (var c = new MySqlData.MySqlClient.MySqlConnection(connection))
            {
                _log.LogTrace <MySqlQuery>($"SELECT: {sql}. Parameters: {JsonConvert.SerializeObject(parameters)}");

                await c.OpenAsync();

                var query = await c.QueryAsync <T>(sql, parameters);

                result = query.ToList();

                await c.CloseAsync();
            }

            return(result.ToList());
        }