{"record":{"id":"4ab0a146d41a03bd","repo":"dotnet/efcore","slug":"the-number-of-key-values-valuescount-doesn-t-m-4ab0a1","errorCode":null,"errorMessage":"The number of key values ({valuesCount}) doesn't match the number of key columns ({columnsCount}) for the data modification operation on '{table}'. Provide the same number of key values and key columns.","messagePattern":"The number of key values \\((.+?)\\) doesn't match the number of key columns \\((.+?)\\) for the data modification operation on '(.+?)'\\. Provide the same number of key values and key columns\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Relational/Migrations/MigrationsSqlGenerator.cs","lineNumber":1060,"sourceCode":"        }\n\n        builder.Append(sqlBuilder.ToString());\n        EndStatement(builder);\n    }\n\n    /// <summary>\n    ///     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","sourceCodeStart":1042,"sourceCodeEnd":1078,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Relational/Migrations/MigrationsSqlGenerator.cs#L1042-L1078","documentation":"Thrown when an UpdateData operation's KeyValues 2D array second dimension does not match the number of KeyColumns. Each row of KeyValues must contain exactly one value per key column so EF can build a correct WHERE clause.","triggerScenarios":"migrationBuilder.UpdateData(...) where keyValues.GetLength(1) (values per row) != keyColumns.Length. Triggered in GenerateModificationCommands(UpdateDataOperation) at the first shape check.","commonSituations":"Composite key where one column was forgotten in keyValues. Passing a jagged-looking 2D array mis-sized. Editing a generated migration and dropping a key column without resizing values.","solutions":["Resize the keyValues 2D array so its second dimension equals keyColumns.Length.","Add the missing key column to both keyColumns and each row of keyValues.","Re-scaffold the migration with dotnet ef migrations add to regenerate consistent arrays."],"exampleFix":"// before\nmigrationBuilder.UpdateData(\n    table: \"Users\",\n    keyColumns: new[] { \"TenantId\", \"Id\" },\n    keyValues: new object[,] { { 1 } }, // 1 value, 2 key columns\n    columns: new[] { \"Name\" },\n    values: new object[,] { { \"x\" } });\n\n// after\nmigrationBuilder.UpdateData(\n    table: \"Users\",\n    keyColumns: new[] { \"TenantId\", \"Id\" },\n    keyValues: new object[,] { { 1, 10 } },\n    columns: new[] { \"Name\" },\n    values: new object[,] { { \"x\" } });","handlingStrategy":"validation","validationCode":"static void CheckKeyShape(string[] keyColumns, object[,] keyValues, string table)\n{\n    if (keyValues.GetLength(1) != keyColumns.Length)\n        throw new ArgumentException($\"{table}: keyValues second dimension must equal keyColumns.Length\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Build keyValues with explicit dimensions matching keyColumns.","When editing migrations, recompute both dimensions together.","Re-scaffold migrations rather than hand-editing composite keys."],"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"}