{"record":{"id":"593ec50b73b23266","repo":"dotnet/efcore","slug":"the-number-of-values-valuescount-doesn-t-match-593ec5","errorCode":null,"errorMessage":"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.","messagePattern":"The number of values \\((.+?)\\) doesn't match the number of columns \\((.+?)\\) for the data modification operation on '(.+?)'\\. Provide the same number of values and columns\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Relational/Migrations/MigrationsSqlGenerator.cs","lineNumber":1067,"sourceCode":"    ///     Generates the commands that correspond to the given operation.\n    /// </summary>\n    /// <param name=\"operation\">The data operation to generate commands for.</param>\n    /// <param name=\"model\">The model.</param>\n    /// <returns>The commands that correspond to the given operation.</returns>\n    protected virtual IEnumerable<IReadOnlyModificationCommand> GenerateModificationCommands(\n        UpdateDataOperation operation,\n        IModel? model)\n    {\n        if (operation.KeyColumns.Length != operation.KeyValues.GetLength(1))\n        {\n            throw new InvalidOperationException(\n                RelationalStrings.UpdateDataOperationKeyValuesCountMismatch(\n                    operation.KeyValues.GetLength(1), operation.KeyColumns.Length, FormatTable(operation.Table, operation.Schema)));\n        }\n\n        if (operation.Columns.Length != operation.Values.GetLength(1))\n        {\n            throw new InvalidOperationException(\n                RelationalStrings.UpdateDataOperationValuesCountMismatch(\n                    operation.Values.GetLength(1), operation.Columns.Length, FormatTable(operation.Table, operation.Schema)));\n        }\n\n        if (operation.KeyValues.GetLength(0) != operation.Values.GetLength(0))\n        {\n            throw new InvalidOperationException(\n                RelationalStrings.UpdateDataOperationRowCountMismatch(\n                    operation.Values.GetLength(0), operation.KeyValues.GetLength(0), FormatTable(operation.Table, operation.Schema)));\n        }\n\n        if (operation.KeyColumnTypes != null\n            && operation.KeyColumns.Length != operation.KeyColumnTypes.Length)\n        {\n            throw new InvalidOperationException(\n                RelationalStrings.UpdateDataOperationKeyTypesCountMismatch(\n                    operation.KeyColumnTypes.Length, operation.KeyColumns.Length, FormatTable(operation.Table, operation.Schema)));\n        }","sourceCodeStart":1049,"sourceCodeEnd":1085,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Relational/Migrations/MigrationsSqlGenerator.cs#L1049-L1085","documentation":"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.","triggerScenarios":"migrationBuilder.UpdateData(...) where values.GetLength(1) != columns.Length. Checked immediately after the key-values shape check in GenerateModificationCommands(UpdateDataOperation).","commonSituations":"Adding a column to columns: ['A','B'] but providing only one value per row. Editing generated migrations and forgetting to update the values matrix.","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."],"exampleFix":"// before\nmigrationBuilder.UpdateData(\n    table: \"Users\",\n    keyColumns: new[] { \"Id\" },\n    keyValues: new object[,] { { 10 } },\n    columns: new[] { \"FirstName\", \"LastName\" },\n    values: new object[,] { { \"Ann\" } }); // 1 value, 2 columns\n\n// after\nmigrationBuilder.UpdateData(\n    table: \"Users\",\n    keyColumns: new[] { \"Id\" },\n    keyValues: new object[,] { { 10 } },\n    columns: new[] { \"FirstName\", \"LastName\" },\n    values: new object[,] { { \"Ann\", \"Smith\" } });","handlingStrategy":"validation","validationCode":"static void CheckValueShape(string[] columns, object[,] values, string table)\n{\n    if (values.GetLength(1) != columns.Length)\n        throw new ArgumentException($\"{table}: values second dimension must equal columns.Length\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["ef-core","migrations","updatedata","argument-validation"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}