コード例 #1
0
        public async Task <List <T> > GetAsync <T>(string sql, object parameters)
        {
            var result = new List <T>();

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

                await connection.OpenAsync();

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

                result = query.ToList();

                await connection.CloseAsync();
            }

            return(result.ToList());
        }
コード例 #2
0
ファイル: MySqlQuery.cs プロジェクト: mrogunlana/Panama.Core
        public List <T> Get <T>(Definition definition)
        {
            var result     = new List <T>();
            var connection = definition.Connection;

            if (string.IsNullOrEmpty(connection))
            {
                connection = _connection;
            }

            using (var mysql = new MySqlData.MySqlConnection(connection))
            {
                _log.LogTrace <MySqlQuery>($"SELECT: {definition.Sql}. Connection: {connection}. Parameters: {JsonConvert.SerializeObject(definition.Parameters)}");

                mysql.Open();

                result = mysql.QueryAsync <T>(new CommandDefinition(definition.Sql, definition.Parameters, cancellationToken: definition.Token, commandTimeout: definition.CommandTimeout)).GetAwaiter().GetResult().ToList();

                mysql.Close();
            }

            return(result.ToList());
        }