/// <summary> /// Builds a script that will update data from the specified <see cref="LogTableRecord" />. /// </summary> /// <param name="table">The <see cref="LogTableDefinition" /> for the database table.</param> /// <param name="record">The <see cref="LogTableRecord" /> containing the data to update.</param> /// <returns>A <see cref="SqlCommand" /> for an UPDATE script that updates the data from the specified <see cref="LogTableRecord" />.</returns> /// <exception cref="ArgumentNullException"> /// <paramref name="table" /> is null. /// <para>or</para> /// <paramref name="record" /> is null. /// </exception> public static SqlCommand BuildUpdate(LogTableDefinition table, LogTableRecord record) { if (table == null) { throw new ArgumentNullException(nameof(table)); } if (record == null) { throw new ArgumentNullException(nameof(record)); } SqlParameterHelper helper = new SqlParameterHelper(table, record); StringBuilder script = new StringBuilder(); script.Append($"UPDATE [dbo].[{table.Name}] SET "); script.Append(string.Join(", ", helper.GetUpdateAssignments())); script.Append(" WHERE "); script.Append(helper.GetPrimaryKeyWhereClause()); // Add parameters for all values SqlCommand command = new SqlCommand(script.ToString()); command.Parameters.AddRange(helper.GetSqlParameters().ToArray()); return(command); }