{"record":{"id":"39dc92f86db5b084","repo":"dotnet/efcore","slug":"incompatiblecomplextypesinassignment","errorCode":"IncompatibleComplexTypesInAssignment","errorMessage":"The complex types '{complexType1}' and '{complexType2}' are being assigned, but the latter is lacking property '{property}' of the former.","messagePattern":"The complex types '(.+?)' and '(.+?)' are being assigned, but the latter is lacking property '(.+?)' of the former\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.ExecuteUpdate.cs","lineNumber":554,"sourceCode":"                    {\n                        throw new InvalidOperationException(\n                            RelationalStrings.ExecuteUpdateOverJsonIsNotSupported(nestedTargetComplexProperty.ComplexType.DisplayName()));\n                    }\n\n                    var nestedTargetExpression =\n                        (StructuralTypeShaperExpression)targetProjection.BindComplexProperty(nestedTargetComplexProperty);\n\n                    // If the value expression is a shaper with its own complex type (as opposed to a constant/parameter), we're assigning\n                    // one (modeled) column to another. In that case, find the corresponding property on the value complex type (which is\n                    // different than the target complex type, despite the two having the same CLR type, e.g. compare ShippingAddress to\n                    // BillingAddress).\n                    // Otherwise, if the value expression is a constant/parameter, just use the target complex property.\n                    var nestedValueComplexProperty = valueExpression is StructuralTypeShaperExpression\n                    {\n                        StructuralType: IComplexType valueNestedComplexType\n                    }\n                        ? valueNestedComplexType!.FindComplexProperty(nestedTargetComplexProperty.Name)\n                        ?? throw new InvalidOperationException(\n                            RelationalStrings.IncompatibleComplexTypesInAssignment(\n                                targetNestedComplexType.DisplayName(), valueNestedComplexType.DisplayName(),\n                                nestedTargetComplexProperty.Name))\n                        : nestedTargetComplexProperty;\n\n                    var nestedValueExpression = CreateComplexPropertyAccessExpression(valueExpression, nestedValueComplexProperty);\n\n                    ProcessComplexType(nestedTargetExpression, nestedValueExpression);\n                }\n\n                Expression CreatePropertyAccessExpression(Expression target, IProperty property)\n                {\n                    return target is LambdaExpression lambda\n                        ? Expression.Lambda(Core(lambda.Body, property), lambda.Parameters[0])\n                        : Core(target, property);\n\n                    Expression Core(Expression target, IProperty property)\n                    {","sourceCodeStart":536,"sourceCodeEnd":572,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.ExecuteUpdate.cs#L536-L572","documentation":"When assigning one complex-type column to another (line 549-558), EF looks up a matching complex property by name on the value's complex type. If the value's complex type is missing a complex property that the target has (same CLR type but different model shape, e.g. ShippingAddress vs BillingAddress where only one has a County sub-object), IncompatibleComplexTypesInAssignment is thrown naming the missing property.","triggerScenarios":"SetProperty assigning a value whose StructuralTypeShaperExpression complex type lacks a nested complex property present on the target, e.g. SetProperty(e => e.BillingAddress, e => e.ShippingAddress) where ShippingAddress has a nested complex property that BillingAddress does not.","commonSituations":"Two complex types sharing the same CLR type but configured differently in the model; partial configuration of one complex type (a property was configured on one but not the other); refactoring where a nested value object was added to one side only.","solutions":["Configure both complex types identically so they have the same set of nested complex properties.","Instead of assigning one complex column to another, assign scalar properties individually.","Pass a constant/parameter of the CLR type rather than a cross-column shaper reference so the target's own structure is used."],"exampleFix":"// before (ShippingAddress has nested Region that BillingAddress lacks)\ndb.Customers.ExecuteUpdate(s => s.SetProperty(\n    c => c.BillingAddress, c => c.ShippingAddress));\n\n// after (configure both complex types identically, or update scalars)\nmodelBuilder.Entity<Customer>()\n    .ComplexProperty(c => c.BillingAddress, a => a.ComplexProperty(x => x.Region))\n    .ComplexProperty(c => c.ShippingAddress, a => a.ComplexProperty(x => x.Region));","handlingStrategy":"validation","validationCode":"// Ensure two complex types share the same nested complex property names before cross-assigning.\nvar targetNames = targetComplexType.GetComplexProperties().Select(p => p.Name);\nvar valueNames = valueComplexType.GetComplexProperties().Select(p => p.Name);\nvar missing = targetNames.Except(valueNames).ToList();\nif (missing.Any()) throw new InvalidOperationException($\"Value complex type missing: {string.Join(\", \", missing)}\");","typeGuard":null,"tryCatchPattern":"try { await q.ExecuteUpdateAsync(s => s.SetProperty(e => e.Billing, e => e.Shipping)); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"lacking property\"))\n{ /* configure both complex types identically, or assign scalars individually */ }","preventionTips":["Configure complex types sharing a CLR type with identical nested property sets.","Prefer assigning scalar sub-properties over whole complex columns.","Pass a captured constant value so the target's own structure is used."],"tags":["efcore","executeupdate","complex-type","setproperty"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}