dotnet/efcore · error · InvalidOperationException
The number of values
Error message
The number of values ({valuesCount}) doesn't match the number of columns ({columnsCount}) for the data modification operation on '{table}'. Provide the same number of values and columns. What it means
Thrown when an UpdateData operation's Values 2D array second dimension does not match the number of Columns being updated. Each row must provide exactly one value per target column.
Solutions
- Add one value per column to every row of the values array so values.GetLength(1) == columns.Length.
- Remove the extra column from columns: if it should not be updated.
- Re-scaffold the migration to regenerate the operation.
Example fix
// before
migrationBuilder.UpdateData(
table: "Users",
keyColumns: new[] { "Id" },
keyValues: new object[,] { { 10 } },
columns: new[] { "FirstName", "LastName" },
values: new object[,] { { "Ann" } }); // 1 value, 2 columns
// after
migrationBuilder.UpdateData(
table: "Users",
keyColumns: new[] { "Id" },
keyValues: new object[,] { { 10 } },
columns: new[] { "FirstName", "LastName" },
values: new object[,] { { "Ann", "Smith" } }); Defensive patterns
Strategy: validation
Validate before calling
static void CheckValueShape(string[] columns, object[,] values, string table)
{
if (values.GetLength(1) != columns.Length)
throw new ArgumentException($"{table}: values second dimension must equal columns.Length");
} Prevention
- Construct columns and values arrays together from a single source.
- After adding a column, immediately add a value to every row.
- Add a migration linter that walks UpdateData operations and verifies dimensions.
When it happens
Trigger: migrationBuilder.UpdateData(...) where values.GetLength(1) != columns.Length. Checked immediately after the key-values shape check in GenerateModificationCommands(UpdateDataOperation).
Common situations: Adding a column to columns: ['A','B'] but providing only one value per row. Editing generated migrations and forgetting to update the values matrix.
Related errors
- The number of column types
- The number of key column types
- The number of key values
- The number of value rows
- values were provided in CreateIndexOperations.IsDescending…
AI-assisted analysis of dotnet/efcore@3a2006ef56 (2026-08-11).
Data as JSON: /api/errors/593ec50b73b23266.
Report an issue: GitHub.
Appendix: source
Thrown at src/EFCore.Relational/Migrations/MigrationsSqlGenerator.cs:1067
/// Generates the commands that correspond to the given operation.
/// </summary>
/// <param name="operation">The data operation to generate commands for.</param>
/// <param name="model">The model.</param>
/// <returns>The commands that correspond to the given operation.</returns>
protected virtual IEnumerable<IReadOnlyModificationCommand> GenerateModificationCommands(
UpdateDataOperation operation,
IModel? model)
{
if (operation.KeyColumns.Length != operation.KeyValues.GetLength(1))
{
throw new InvalidOperationException(
RelationalStrings.UpdateDataOperationKeyValuesCountMismatch(
operation.KeyValues.GetLength(1), operation.KeyColumns.Length, FormatTable(operation.Table, operation.Schema)));
}
if (operation.Columns.Length != operation.Values.GetLength(1))
{
throw new InvalidOperationException(
RelationalStrings.UpdateDataOperationValuesCountMismatch(
operation.Values.GetLength(1), operation.Columns.Length, FormatTable(operation.Table, operation.Schema)));
}
if (operation.KeyValues.GetLength(0) != operation.Values.GetLength(0))
{
throw new InvalidOperationException(
RelationalStrings.UpdateDataOperationRowCountMismatch(
operation.Values.GetLength(0), operation.KeyValues.GetLength(0), FormatTable(operation.Table, operation.Schema)));
}
if (operation.KeyColumnTypes != null
&& operation.KeyColumns.Length != operation.KeyColumnTypes.Length)
{
throw new InvalidOperationException(
RelationalStrings.UpdateDataOperationKeyTypesCountMismatch(
operation.KeyColumnTypes.Length, operation.KeyColumns.Length, FormatTable(operation.Table, operation.Schema)));
}View on GitHub (pinned to 3a2006ef56)