{"record":{"id":"b8a23ed2b9a8593a","repo":"dotnet/efcore","slug":"the-number-of-value-rows-valuescount-doesn-t-m","errorCode":null,"errorMessage":"The number of value rows ({valuesCount}) doesn't match the number of key rows ({keyCount}) for the data modification operation on '{table}'. Provide the same number of value rows and key rows.","messagePattern":"The number of value rows \\((.+?)\\) doesn't match the number of key rows \\((.+?)\\) for the data modification operation on '(.+?)'\\. Provide the same number of value rows and key rows\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Relational/Migrations/MigrationsSqlGenerator.cs","lineNumber":1074,"sourceCode":"        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        }\n\n        if (operation.ColumnTypes != null\n            && operation.Columns.Length != operation.ColumnTypes.Length)\n        {\n            throw new InvalidOperationException(\n                RelationalStrings.UpdateDataOperationTypesCountMismatch(\n                    operation.ColumnTypes.Length, operation.Columns.Length, FormatTable(operation.Table, operation.Schema)));","sourceCodeStart":1056,"sourceCodeEnd":1092,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Relational/Migrations/MigrationsSqlGenerator.cs#L1056-L1092","documentation":"Thrown when an UpdateData operation provides a different number of key rows vs value rows. EF requires KeyValues.GetLength(0) (number of rows to update) to equal Values.GetLength(0); every key row must have a corresponding value row.","triggerScenarios":"migrationBuilder.UpdateData(...) where the first dimension of keyValues (rows) differs from the first dimension of values (rows). E.g. two key rows but one value row.","commonSituations":"Batch-updating multiple rows and forgetting to extend one of the matrices. Copy-paste errors when adding a new row to only keyValues or only values.","solutions":["Ensure both keyValues and values have the same number of rows (first dimension).","If you only have one row to update, remove the extra rows from whichever array is longer.","Re-scaffold the migration to regenerate both matrices from the model."],"exampleFix":"// before\nmigrationBuilder.UpdateData(\n    table: \"Users\",\n    keyColumns: new[] { \"Id\" },\n    keyValues: new object[,] { { 10 }, { 11 } }, // 2 rows\n    columns: new[] { \"Name\" },\n    values: new object[,] { { \"Ann\" } }); // 1 row\n\n// after\nmigrationBuilder.UpdateData(\n    table: \"Users\",\n    keyColumns: new[] { \"Id\" },\n    keyValues: new object[,] { { 10 }, { 11 } },\n    columns: new[] { \"Name\" },\n    values: new object[,] { { \"Ann\" }, { \"Bob\" } });","handlingStrategy":"validation","validationCode":"static void CheckRowCounts(object[,] keyValues, object[,] values, string table)\n{\n    if (keyValues.GetLength(0) != values.GetLength(0))\n        throw new ArgumentException($\"{table}: keyValues row count must equal values row count\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Add key and value rows in pairs.","Parameterize migration builders with a row-list so additions hit both matrices.","Re-scaffold migrations to regenerate consistent row counts."],"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"}