public static int EFInsertUpdate <T>(this MySqlConnection connection, T instance, string table) { using (var cmd = EntityCommandBuilder.BuildInsertUpdateCommand(instance, table, connection)) { return(cmd.ExecuteNonQuery()); } }
public static async Task <int> EFInsertUpdateAsync <T>(this MySqlConnection connection, T instance, string table) { using (var cmd = EntityCommandBuilder.BuildInsertUpdateCommand(instance, table, connection)) { return(await cmd.ExecuteNonQueryAsync()); } }
/// <summary> /// Creates the object in the database table. /// If an item with the same primary or unique key exists, it will update it instead. /// </summary> /// <param name="Obj">The object to create</param> /// <param name="Table">The table to create the object in</param> public async Task InsertUpdateAsync <T>(T Obj, string Table) { using (MySqlConnection connection = GetConnection(autoOpen: false, forceNew: true)) { await connection.OpenAsync(); using (MySqlCommand Command = EntityCommandBuilder.BuildInsertUpdateCommand <T>(Obj, Table, connection)) { await Command.ExecuteNonQueryAsync(); } await connection.CloseAsync(); } }
/// <summary> /// Creates the object in the database table. /// If an item with the same primary or unique key exists, it will update it instead. /// </summary> /// <param name="Obj">The object to create</param> /// <param name="Table">The table to create the object in</param> public void InsertUpdate <T>(T Obj, string Table) { if (ReuseSingleConnection) { lock (ActiveConnection) { using (MySqlCommand Command = EntityCommandBuilder.BuildInsertUpdateCommand <T>(Obj, Table, ActiveConnection)) { Command.ExecuteNonQuery(); } } } else { using (MySqlConnection connection = new MySqlConnection(ConnectionString)) { connection.Open(); using (MySqlCommand Command = EntityCommandBuilder.BuildInsertUpdateCommand <T>(Obj, Table, connection)) { Command.ExecuteNonQuery(); } } } }