{"record":{"id":"6d30b499347db8fb","repo":"dotnet/efcore","slug":"the-property-entitytype-property-has-a-value","errorCode":null,"errorMessage":"The property '{entityType}.{property}' has a value generator configured. Use '{method}' to configure the value generator factory type.","messagePattern":"The property '(.+?)\\.(.+?)' has a value generator configured\\. Use '(.+?)' to configure the value generator factory type\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Design/Scaffolding/Internal/CSharpRuntimeModelCodeGenerator.cs","lineNumber":1088,"sourceCode":"                    .Append(_code.UnknownLiteral(providerValue))\n                    .AppendLine(\");\")\n                    .AppendLine();\n            }\n        }\n    }\n\n    private void Create(\n        IProperty property,\n        Dictionary<MemberInfo, QualifiedName>? memberAccessReplacements,\n        CSharpRuntimeAnnotationCodeGeneratorParameters parameters)\n    {\n        var variableName = _code.Identifier(property.Name, property, parameters.ScopeObjects, capitalize: false);\n\n        var valueGeneratorFactoryType = (Type?)property[CoreAnnotationNames.ValueGeneratorFactoryType];\n        if (valueGeneratorFactoryType == null\n            && property.GetValueGeneratorFactory() != null)\n        {\n            throw new InvalidOperationException(\n                DesignStrings.CompiledModelValueGenerator(\n                    property.DeclaringType.ShortName(), property.Name, nameof(PropertyBuilder.HasValueGeneratorFactory)));\n        }\n\n        var mainBuilder = parameters.MainBuilder;\n        mainBuilder\n            .Append(\"var \").Append(variableName).Append(\" = \").Append(parameters.TargetName).AppendLine(\".AddProperty(\")\n            .IncrementIndent()\n            .Append(_code.Literal(property.Name));\n\n        GeneratePropertyBaseParameters(property, parameters);\n\n        if (property.IsNullable)\n        {\n            mainBuilder.AppendLine(\",\")\n                .Append(\"nullable: \")\n                .Append(_code.Literal(true));\n        }","sourceCodeStart":1070,"sourceCodeEnd":1106,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Design/Scaffolding/Internal/CSharpRuntimeModelCodeGenerator.cs#L1070-L1106","documentation":"Thrown in CSharpRuntimeModelCodeGenerator.Create(IProperty) (line 1088, resource CompiledModelValueGenerator) when generating a compiled model for a property that has a value generator configured via a factory instance rather than a factory type. Compiled models can only encode a value-generator factory type, so when a property has GetValueGeneratorFactory() != null but no ValueGeneratorFactoryType annotation, generation aborts and points you to HasValueGeneratorFactory.","triggerScenarios":"Running compiled-model generation for a property configured with HasValueGenerator (an instance-based factory) rather than HasValueGeneratorFactory (a type-based factory). The check `valueGeneratorFactoryType == null && property.GetValueGeneratorFactory() != null` is true and throws CompiledModelValueGenerator(entityType, property, nameof(PropertyBuilder.HasValueGeneratorFactory)).","commonSituations":"Configuring a property with HasValueGenerator(() => new MyGenerator()) and then enabling compiled models. Instance-based generators cannot be serialized into the compiled model source. Switching an existing model to compiled models reveals these instance-based configurations.","solutions":["Replace HasValueGenerator(instance factory) with HasValueGeneratorFactory(typeof(MyGenerator)) so the compiled model can encode the type.","Ensure your value generator has a parameterless constructor so it can be activated from the factory type.","Re-run compiled-model generation after the switch.","If an instance factory is mandatory, exclude the property/entity from compiled-model generation."],"exampleFix":"// before: instance-based value generator blocks compiled models\nmodelBuilder.Entity<Order>()\n    .Property(o => o.Number)\n    .HasValueGenerator(() => new OrderNumberGenerator());\n\n// after: type-based factory the compiled model can encode\nmodelBuilder.Entity<Order>()\n    .Property(o => o.Number)\n    .HasValueGeneratorFactory<OrderNumberGenerator>();","handlingStrategy":"validation","validationCode":"// Detect instance-based value generators before compiled-model generation\nforeach (var et in model.GetEntityTypes())\nforeach (var p in et.GetProperties())\n    if (p[CoreAnnotationNames.ValueGeneratorFactoryType] is null\n        && p.GetValueGeneratorFactory() is not null)\n    { /* switch to HasValueGeneratorFactory<T>() */ }","typeGuard":null,"tryCatchPattern":"try { /* generate compiled model */ }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"value generator\"))\n{ /* switch HasValueGenerator -> HasValueGeneratorFactory<T>(), then retry */ }","preventionTips":["Prefer HasValueGeneratorFactory<T>() over instance-based HasValueGenerator when using compiled models.","Ensure value generators have parameterless constructors."],"tags":["ef-core","compiled-model","value-generator","design-time"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}