{"record":{"id":"add59c661a1d695c","repo":"dotnet/efcore","slug":"the-number-of-column-types-typescount-doesn-t-add59c","errorCode":null,"errorMessage":"The number of column types ({typesCount}) doesn't match the number of columns ({columnsCount}) for the data modification operation on '{table}'. Provide the same number of column types and columns.","messagePattern":"The number of column types \\((.+?)\\) doesn't match the number of columns \\((.+?)\\) for the data modification operation on '(.+?)'\\. Provide the same number of column types and columns\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Relational/Migrations/MigrationsSqlGenerator.cs","lineNumber":1090,"sourceCode":"        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)));\n        }\n\n        if (operation.KeyColumnTypes == null\n            && model == null)\n        {\n            throw new InvalidOperationException(\n                RelationalStrings.UpdateDataOperationNoModel(\n                    FormatTable(operation.Table, operation.Schema)));\n        }\n\n        var keyPropertyMappings = operation.KeyColumnTypes == null\n            ? GetPropertyMappings(operation.KeyColumns, operation.Table, operation.Schema, model)\n            : null;\n        var propertyMappings = operation.ColumnTypes == null\n            ? GetPropertyMappings(operation.Columns, operation.Table, operation.Schema, model)\n            : null;","sourceCodeStart":1072,"sourceCodeEnd":1108,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Relational/Migrations/MigrationsSqlGenerator.cs#L1072-L1108","documentation":"Thrown when an UpdateData operation supplies ColumnTypes whose length differs from Columns. Each updated column must declare its store type when explicit types are in use.","triggerScenarios":"migrationBuilder.UpdateData(...) with columnTypes: array of wrong length. Checked in GenerateModificationCommands(UpdateDataOperation) right after the key-types check.","commonSituations":"Hand-edited update where a target column was added without a matching type entry. Migrations targeting providers that need explicit types (SQLite).","solutions":["Resize columnTypes so its length equals columns length.","Remove columnTypes to let the model resolve store types.","Re-scaffold the migration to produce consistent arrays."],"exampleFix":"// before\nmigrationBuilder.UpdateData(\n    table: \"Users\",\n    keyColumns: new[] { \"Id\" },\n    keyValues: new object[,] { { 10 } },\n    columns: new[] { \"FirstName\", \"LastName\" },\n    columnTypes: new[] { \"nvarchar(50)\" }, // 1 type, 2 columns\n    values: new object[,] { { \"Ann\", \"Smith\" } });\n\n// after\nmigrationBuilder.UpdateData(\n    table: \"Users\",\n    keyColumns: new[] { \"Id\" },\n    keyValues: new object[,] { { 10 } },\n    columns: new[] { \"FirstName\", \"LastName\" },\n    columnTypes: new[] { \"nvarchar(50)\", \"nvarchar(50)\" },\n    values: new object[,] { { \"Ann\", \"Smith\" } });","handlingStrategy":"validation","validationCode":"static void CheckColumnTypeCount(string[] columns, string[]? columnTypes, string table)\n{\n    if (columnTypes is not null && columnTypes.Length != columns.Length)\n        throw new ArgumentException($\"{table}: columnTypes length must equal columns length\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Build columns and columnTypes from the same list.","Omit columnTypes unless the provider requires them.","Re-scaffold migrations after column changes."],"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"}