예제 #1
0
        public void Execute(string connection, string sql, object parameters)
        {
            using (var mysql = new MySqlData.MySqlConnection(connection))
            {
                _log.LogTrace <MySqlQuery>($"EXECUTE: {sql}. Parameters: {JsonConvert.SerializeObject(parameters)}");

                mysql.Open();
                mysql.Execute(sql, parameters);
                mysql.Close();
            }
        }
예제 #2
0
        /// <summary>
        /// Dapper ORM Insert function
        /// </summary>
        /// <param name="t"></param>
        public void Insert(T t, bool emptyStringNull = false)
        {
            var insertQuery = GenerateInsertQuery(t).Replace("上午", "").Replace("下午", "");

            try
            {
                if (emptyStringNull)
                {
                    insertQuery = insertQuery.Replace("''", "null");
                }
                if (!string.IsNullOrEmpty(connString) && sqlConnection != null && sqlConnection.State == System.Data.ConnectionState.Open)
                {
                    log.Debug(insertQuery);
                    if (transaction == null)
                    {
                        sqlConnection.Execute(insertQuery, t);
                        sqlConnection.Close();
                    }
                    else
                    {
                        sqlConnection.Execute(insertQuery, t, transaction);
                    }
                }
                else
                {
                    sqlConnection = new MySqlConnector.MySqlConnection(connString);
                    sqlConnection.Open();
                    //cn.Open();
                    Insert(t, emptyStringNull);
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
                throw ex;
            }
        }