예제 #1
0
 public static async Task <int> EFInsertAsync <T>(this MySqlConnection connection, T instance, string table)
 {
     using (var cmd = EntityCommandBuilder.BuildInsertCommand(instance, table, connection))
     {
         return(await cmd.ExecuteNonQueryAsync());
     }
 }
예제 #2
0
 public static int EFInsert <T>(this MySqlConnection connection, T instance, string table)
 {
     using (var cmd = EntityCommandBuilder.BuildInsertCommand(instance, table, connection))
     {
         return(cmd.ExecuteNonQuery());
     }
 }
예제 #3
0
        /// <summary>
        /// Creates the object in the database table.
        /// </summary>
        /// <param name="Obj">The object to create</param>
        /// <param name="Table">The table to create the object in</param>
        public async Task InsertAsync <T>(T Obj, string Table)
        {
            using (MySqlConnection connection = GetConnection(autoOpen: false, forceNew: true))
            {
                await connection.OpenAsync();

                using (MySqlCommand Command = EntityCommandBuilder.BuildInsertCommand <T>(Obj, Table, connection))
                {
                    await Command.ExecuteNonQueryAsync();
                }
                await connection.CloseAsync();
            }
        }
예제 #4
0
 /// <summary>
 /// Creates the object in the database table.
 /// </summary>
 /// <param name="Obj">The object to create</param>
 /// <param name="Table">The table to create the object in</param>
 public void Insert <T>(T Obj, string Table)
 {
     if (ReuseSingleConnection)
     {
         lock (ActiveConnection)
         {
             using (MySqlCommand Command = EntityCommandBuilder.BuildInsertCommand <T>(Obj, Table, ActiveConnection))
             {
                 Command.ExecuteNonQuery();
             }
         }
     }
     else
     {
         using (MySqlConnection connection = GetConnection())
         {
             connection.Open();
             using (MySqlCommand Command = EntityCommandBuilder.BuildInsertCommand <T>(Obj, Table, connection))
             {
                 Command.ExecuteNonQuery();
             }
         }
     }
 }